Web Service Adding extra forward slash in SOAPAction - asp.net

I am using SoapUI to test a .Net Web Service that will be consumed by a Java client application.
When I hook up my Web Service to SoapUI but updating the WSDL location and call one of the preset testing scripts, the Web Service fails with the following code
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<soap:Fault>
<faultcode>soap:Client</faultcode>
<faultstring>System.Web.Services.Protocols.SoapException: Server did not recognize the value of HTTP Header SOAPAction: urn:mycode:us:gu:das:supplierengagement:v02:SupplierEngagement:/AppointSupplier.
at System.Web.Services.Protocols.Soap11ServerProtocolHelper.RouteRequest()
at System.Web.Services.Protocols.SoapServerProtocol.RouteRequest(SoapServerMessage message)
at System.Web.Services.Protocols.SoapServerProtocol.Initialize()
at System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean& abortProcessing)
</faultstring>
<detail/>
</soap:Fault>
</soap:Body>
</soap:Envelope>
As you can see from the above error, the problem is with the SOAPAction parameter having an extra forward slash.
I am using the following attribute on the class:
<WebService(Namespace:= "urn:mycode:us:gu:das:supplierengagement:v02:SupplierEngagement:AppointSupplier")>
and the following attribute on the method call:
<WebMethod(MessageName:="appointSupplierRq")>
From these, .Net is adding the forward slash.
It must be possible to remove the forward slash that is automatically being generated.

From reviewing the code, creating mock samples and such I don't see the problem. Yes I do see the extra forward slash as you mention in your post however that is by design. That is how the ASMX service notes the method within the class to execute.
Now from your SOAP message and your WebService \ WebMethod attributes there is something out of sync. Your SOAP Header action should be
urn:mycode:us:gu:das:supplierengagement:v02:SupplierEngagement:AppointSupplier/appointSupplierReq
not
urn:mycode:us:gu:das:supplierengagement:v02:SupplierEngagement:/AppointSupplier
This leads me to believe either you haven't updated the SOAP UI project to the new generated WSDL. Try creating a new Project in SOAP UI pointing the WSDL file of the ASMX web service such as.
http://<web host>/SupplierEngagement.asmx?wsdl
And run the test methods. If this does not fix the issue please post (as an edit) the full class for the SupplierEngagement asmx file (you can omit the method content) as we are only really interested in the full setup.

I had a similar issue that was finally a permissions issues on the server side that was providing the forward slash error, but other things can be done to diagnose the problem
Can the SoapAction of a SOAP REQUEST be altered by interoperability issues between .NET and JAVA or a network/infraestructure proxy

Related

Adding Headers to Soap Request .Net

I added a web service reference to my existing visual studio project, I not able to execute any of the service methods as i keep getting "missing headers" error.
Then newly generated proxy class doesn't have method to add headers. Is there a way i can add http header to the request
Override the method GetWebRequest in the proxy class
Then add below code
HttpWebRequest request = base.GetWebRequest();
request.Headers.Add("HeaderName", "HeaderValue");
return request

How to get Http header values in Apache Camel- Jersey Rest API

I have an application which uses Apache Camel to build an API. It basically uses blueprint.xml to define routes and processing is done by a bean(please note its not any processor bean. Just a plain Java bean). It uses Jersey client to invoke the backend system Rest API.
My requirement is to get the http headers in the code to be able to send them to our custom logging system.
a) I tried #httpHeaders annotation but this does not inject the headers on my code.
b) Since its not using any BeanProcessor i dont have an Exchange object from where i can get the header values.
Please help with a way to get header values on the code.
Add the request context to your class
#Context
private HttpServletRequest request;
and get the headers in your endpoint using request.getHeader
Returns the value of the specified request header as a String.

.NET soap web service that returns JSON- how does it work?

I don't have something in particular that I need to implement, I am just trying to understand some concepts.
As far as I know, .NET web method (for example), that is inside a web service, is using the SOAP protocol. that means that the data received to the server needs to be in XML format, and the data that is returned from the web method should also be in XML format.
I know I can write something like this:
[WebMethod]
public static Object someMethod(Object josn)
{
Console.Write(json("someProperty"));
return new {name = "John"}
}
I know that data sent back to the client is in JSON format...
but if we are using the SOAP protocol, shouldn't it return XML?
I want to understand what is happening behind the scene or what am I missing, does the request was sent in xml format and the .NET framework knows how to extract the parameters that were sent, if so- how can I retrieve the full xml that represents the request made?
What you are referring to is called the SOAP envelope. Take a look here:
Sample SOAP Envelope
One of the easiest ways to see the SOAP envelope that is being used in a request or response is to use Fiddler or Postman.
EDIT
Here's an example of WCF SOAP envelope with JSON (not sure if you are using WCF or the old .NET Web Service with ASMX files):
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing">
<s:Header></s:Header>
<s:Body>[{"DateOfBirth":"\/Date(286801200000+1300)\/","FirstName":"Foo","Id":1,"LastName":"Bar"},{"DateOfBirth":"\/Date(333720000000+1200)\/","FirstName":"Foo","Id":1,"LastName":"Bar"}]</s:Body>
</s:Envelope>

how to consume .svc file

I have got url for svc file. For example https://Myservicelocation/UserService.svc.
Now i tried to create asp.net web application in visual studio and added this url using "Add service reference". When i put this url and then click go i get error
The request failed with HTTP status 400: Bad Request.
Metadata contains a reference that cannot be resolved: 'https://Myservicelocation/UserService.svc'.
Content Type application/soap+xml; charset=utf-8 was not supported by service https://Myservicelocation/UserService.svc. The client and service bindings may be mismatched.
The remote server returned an error: (415) Cannot process the message because the content type 'application/soap+xml; charset=utf-8' was not the expected type 'text/xml; charset=utf-8'..
If the service is defined in the current solution, try building the solution and adding the service reference again.
How can i resolve this?
Google says..
Probably a mismatch in the client/server bindings, where the message version in the service uses SOAP 1.1 (which expects application/soap+xml) and the version in the client uses SOAP 1.2 (which sends text/xml). WSHttpBinding uses SOAP 1.2, BasicHttpBinding uses SOAP 1.1.
Align your bindings accordingly...
I had the same problem.
Try https://Myservicelocation/UserService.svc?wsdl link.

asp.net not deserializing soap response

I have been given a wsdl and have used wsdl.exe to create my proxy classes.
I am able to call the function to initiate the request with some valid parameters and this returns my response object which is always EMPTY.
When i inspect the soap message response using fiddler the soap does have valid data that should be deserialzed to the proxy classes.
Can i manually intercept the derserializing call of the proxy classes generated by wsdl and check that .net is correctly derializing the soap response?
Thank you
The empty object is most likely the result of a mismatch between the soap message and your proxy class. This can for example be caused by a difference in namespaces (newer version).

Resources