function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
ABCDEFGHIJKLMNOABCDEFGHIJKLMNO 

Adding Namespace to Webservice Class Name

I have almost gotten my webservice working, first in dev, then in prod, due to the help I've been getting on here. Thanks, Simon!

 

Last question, I hope: I added a namespace to my webservice so that the package could be managed and now it fails with the error message "No service available for class [CLASSNAME]". I found some posts on here that said to resolve this, I need to add the namespace to my classname.

 

How? I tried changing the classname in the service, but the package is now managed and therefore won't let me.

 

I am calling the webservice from C#. I regenerated the WSDL after adding the namespace, and my interface code is generated from the WSDL. I'm not sure where I could add the namespace in this.

 

Or is there something else going on?

 

TIA,

Best Answer chosen by Admin (Salesforce Developers) 
ABCDEFGHIJKLMNOABCDEFGHIJKLMNO
There was an orphaned reference to the OLD webservice in the app.config file in one of the projects. When I removed that, everything started working. Thanks Simon!

All Answers

SuperfellSuperfell
Make sure you've imported the new WSDL, and are using the new service URL from that WSDL.
ABCDEFGHIJKLMNOABCDEFGHIJKLMNO

I imported the new WSDL. It has changed since I added the namespace:

 

- <definitions targetNamespace=http://soap.sforce.com/schemas/class/NAMESPACE/CLASSNAME xmlns:xsd="http://www.w3.org/2001/XMLSchema" ...

 

By this I mean that the NAMESPACE element was not there before. I think this is what you mean by the new service URL:

 

<soap:address location="https://na4-api.salesforce.com/services/Soap/class/NAMESPACE/CLASSNAME"/>

 

Again, the NAMESPACE element was not there before. The autogenerated reference.cs code file also refers to the new namespace, I think:

 

[System.Web.Services.WebServiceBindingAttribute(Name="CLASSNAMEBinding", Namespace=http://soap.sforce.com/schemas/class/NAMESPACE/CLASSNAME)]

 

So I'm pretty sure that I have imported the correct WSDL.

 

I have also verified that the webservice class has permissions for the API user making the call.

 

But I keep getting the same "No service available for class CLASSNAME" error message.

 

It does occur to me that I don't really know what you mean by "[you] are using the new service URL from that WSDL". If I import the WSDL, that's all I have to do, right?

 

TIA,

 

John

ABCDEFGHIJKLMNOABCDEFGHIJKLMNO
Just to be sure, I tested the webservice using a different user with full system administrator credentials and got the same error.
ABCDEFGHIJKLMNOABCDEFGHIJKLMNO

This is the actual call that is failing (from reference.cs):

 

[System.Web.Services.Protocols.SoapHeaderAttribute("DebuggingHeaderValue")] [System.Web.Services.Protocols.SoapHeaderAttribute("AllowFieldTruncationHeaderValue")] [System.Web.Services.Protocols.SoapHeaderAttribute("SessionHeaderValue")] [System.Web.Services.Protocols.SoapHeaderAttribute("DebuggingInfoValue", Direction=System.Web.Services.Protocols.SoapHeaderDirection.Out)] [System.Web.Services.Protocols.SoapHeaderAttribute("CallOptionsValue")] [System.Web.Services.Protocols.SoapDocumentMethodAttribute("", RequestNamespace=http://soap.sforce.com/schemas/class/NAMESPACE/CLASSNAME, ResponseNamespace=http://soap.sforce.com/schemas/class/NAMESPACE/CLASSNAME, Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)] [return: System.Xml.Serialization.XmlElementAttribute("result", IsNullable=true)] public validationResult validate([System.Xml.Serialization.XmlElementAttribute(IsNullable=true)] validationRequest request) { object[] results = this.Invoke("validate", new object[] { request}); return ((validationResult)(results[0])); }

 

 

 

ABCDEFGHIJKLMNOABCDEFGHIJKLMNO

I found some instructions in the Force.com Web Services API (http://www.salesforce.com/us/developer/docs/api/index.htm) that said:

 

To access an XML Web service from managed code: Add a Web reference to your project for the XML Web service that you want to access. The Web reference creates a proxy class with methods that serve as proxies for each exposed method of the XML Web service. Add the namespace for the Web reference. Create an instance of the proxy class and then access the methods of that class as you would the methods of any other class. To add a Web reference: On the Project menu, choose Add Web Reference. In the URL box of the Add Web Reference dialog box, type the URL to obtain the service description of the XML Web service you want to access, such as: file:///c:\WSDLFiles\enterprise.wsdl Click Go to retrieve information about the XML Web service. In the Web reference name box, rename the Web reference to sforce, which is the namespace you will use for this Web reference. Click Add Reference to add a Web reference for the target XML Web service. For more information, see the topic “Adding and Removing Web References” in the Visual Studio documentation. Visual Studio retrieves the service description and generates a proxy class to interface between your application and the XML Web service.

 

 

Obviously this is intended for Force.com but I assume it applies to any web service, so I changed my web reference name to be the same as my namespace.

 

Same error.

SuperfellSuperfell
well, there are configs and programatic ways to change the Url property on the stub, so just importing the new WSDL may not be enough to pick up the new URL, depending on how your application is built. check the .url property on your stub just before making the call that's failing.
ABCDEFGHIJKLMNOABCDEFGHIJKLMNO
There was an orphaned reference to the OLD webservice in the app.config file in one of the projects. When I removed that, everything started working. Thanks Simon!
This was selected as the best answer
GoForceGoGoForceGo

I am getting a similar issue when I point my Java code to a different Sandbox instance (cs3 instead of cs2). I have a webservice generated for an Apex Class. 

 

I am already repointing to the server URL that I get.

 

 

  SforceServiceLocator slocator = new SforceServiceLocator();

if (config.isSandbox()) {
logger.info("Logging into Sandbox");
slocator.setSoapEndpointAddress(Constants.SandboxSoapEndPoint);
}
binding = (SoapBindingStub)slocator.getSoap();
loginResult = binding.login(config.getUserName(), config.getPwd());
binding._setProperty(SoapBindingStub.ENDPOINT_ADDRESS_PROPERTY, loginResult.getServerUrl());
SessionHeader sh = new SessionHeader();
sh.setSessionId(loginResult.getSessionId());
binding.setHeader(new SforceServiceLocator().getServiceName().getNamespaceURI(), "SessionHeader", sh);





 

Seems like the issue is probably something to do with the  SOAP Address in the WSDL.

 

 

 

<service name="MyWebService">
<documentation/>

<port binding="tns:MyWebServiceBinding" name="MyWebService">
<soap:address location="https://cs2-api.salesforce.com/services/Soap/class/MyWebService"/>
</port>
</service>

 

 

 

 

 

Message Edited by GoForceGo on 03-31-2009 11:23 AM