I have imported a WSDL via the Service Reference dialog box in VS2010 (asmx not WCF) which contains a SendMessage method which I need to call, passing it Xml and a Command name. I'm also passing the URL of the WS. When I call this method, it causes the following exception:
SoapHeaderException: Soap Header Action Not Understood
I think I am able to read the Soap request via Fiddler, and it contains no Soap Header information. I would have expected C# to add this automatically since all the required information to create it is present.
How do I ensure the Soap Header is added??
Related
I need to call an external SOAP webservice over HTTP.
I have the WSDL file and added it in Visual Studio via 'Add service reference'. Visual studio then added a number of files, in the reference file i can find this:
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
[System.ServiceModel.ServiceContractAttribute(ConfigurationName="Service.IService")]
public interface IService {
[System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IService/Function", ReplyAction="http://tempuri.org/IService/FunctionResponse")]
namespace.Service.ExecuteFunctionResponse ExecuteFunction(namespace.Service.FunctionRequest request);
}
With additionaly the async version of this call and the objects for sending an receiving, etc.
To call the service I added the folowing code:
BasicHttpBinding binding = new BasicHttpBinding();
EndpointAddress endpointAddress = new EndpointAddress("the address");
serviceChannel = new ServiceClient(binding, endpointAddress).ChannelFactory.CreateChannel();
Response response = serviceChannel.ExecuteFunction(new Request(...));
This results in me getting an exception, error 405 method not allowed.
So it appears I must use a HTTP GET request instead of the default POST request. But i cannot find where this can be altered in with this way of working.
So, where can i set the HTTP method for this call to a webservice?
SOAP services are using HTTP POST because they exchange XML messages (which tend to be complex) and cannot be transferred in a query string.
Are you sure that you must use HTTP GET? Maybe the error you are receiving "405 method not allowed" is caused by some bad configuration.
I would double check the SOAP endpoint URL is set correctly and check that there are no additional security requirements needed.
EDIT
In past, there was a practice to create ASP.NET Web Services which would accept GET as well. But they wouldn't expect XML messages. Instead, you would have to pass all parameters in a querystring. For example: https://foo.bar/service.asmx/Func?param1=X¶m2=Y (where param1 and param2 are the expected parameters).
This way it is possible to call a WebService without a need for WSDL and using GET method. You can achieve it by using HttpClient for example.
The downside of this approach is that you will have to deal with plain data instead of objects.
I hope it might help.
I imported a WSDL into my project for a 3rd party system. (The WSDL is a nightmare)
Anyway in order for my request to receive a valid response i have been told by the 3rd party i need to send through an empty object in one of the requests.
Lets assume a valid request looks like the below:
<Request>
<UserID>123456</UserID>
<ComplexObj/>
</Request>
If i send the above XML manually in SOAP UI then I get a valid response.
However because I'm doing this in C# i have imported the WSDL into visual studio and have a service reference generated i cannot figure out a way for the request to generate the empty ComplexObj.
If i set ComplexObj to null in the code it is not included in the request.
If i create a new instance of the ComplexObj then the request includes all the variables within the ComplexObj which is also invalid.
HAve you tried to declare ComplexObjproperty to serialize even if it is null. For that you'll need to find the definition of class and add
[System.Xml.Serialization.XmlElementAttribute(IsNullable=true)]
for that property. That 'll include it into SOAP request as <ComplexObj xsi:nil="true" />
I have added a Service Reference that points to WSDL of the service. I can consume the service by creating a proxy and theres no issue with that. My problem is that I need to send a specific soap message , and theres some parameters that need to be include into the header and the body of the soap message (credentials and IDs).
How I can manually edit or add this soap message? without touching the app.config file?, there's a way to add the same parameters inside the code? such as:
soap:Header
soap:Body
one of my friend made a soap webservice in PHP and now i have to consume it into my winform app. I added web Service Reference , pasted the URL and it is showing method name.
The method name is Display().
Now after adding when write code on button click, it is showing following three methods:
MyWebServiceName. DisplayCompletedEventArgs
DisplayCompletedEventHandler
SiteControllerService
There is no soapClient or direct Display method ,any one know , what am I doing wrong?
Check the WSDLyou must have in the VS project. You will find the service name:
Ex:
<wsdl:service name="SiteControllerService">
So you must type:
MyWebServiceName.SiteControllerService SOAPclient = new MyWebServiceName.SiteControllerService();
SOAPClient.Display();
Visual Strudio create a namespace to encapsulate all classes generated to work with the web service. In that namespace you will find the soap proxy client, events and events handler and any data transfer object needed to pass parameters to proxy client or to recive the response.
I am trying to make an asynchronous call to a web service using BeginXXX and EndXXX methods from C# client. I am using a proxy class generated by using SvcUtil.exe.
The soap message that I expect to send should contain soap header elements for ws-addressing which include tags:
'wsa:Action'
'wsa:MessageID'
'wsa:ReplyTo'
'wsa:To'
However the soap header section is currently empty and only soap body contains body information.
Without the wsa tags, it looks like a synchronous call.
Is there a way to use proxy generated in C#, to invoke a service asynchronously such that the soap message contains wsa tags?
Appreciate any input with regards to this