C# SOAP-Service Missing namespace on Method Parameters - c#

I am facing a problem with my webservice written in C#. It works fine until I want to call method with parameters, the SOAP Request generated from an external supplier using my wsdl looks like the following:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<s:Header xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<To s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">http://127.0.0.1/AService</To>
<Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">ANameSpace/login</Action>
</s:Header>
<soapenv:Body>
<ns1:login soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="ANameSpace">
<a_sDMSUserName xsi:type="xsd:string">test</a_sDMSUserName>
<a_sDMSUserPassword xsi:type="xsd:string">oscar</a_sDMSUserPassword>
</ns1:login>
</soapenv:Body>
</soapenv:Envelope>
This is a part of the interface of my Service:
[ServiceContract (Namespace ="ANameSpace")]
public interface IFordEcat
{
[OperationContract (Action ="ANameSpace/connect")]
int connect();
[OperationContract(Action = "ANameSpace/disconnect")]
int disconnect();
[OperationContract(Action = "ANameSpace/login")]
string login(string a_sDMSUserName, string a_sDMSUserPassword);
[OperationContract(Action = "ANameSpace/logout")]
string logout(string a_sSessionID, string a_sDMSUserName, string a_sDMSUserPassword);
With SoapUI or a test client setup in C# via Service Reference it works fine.
The only problem is that the parameters of the login Method or any other Method with parameters, are missing the namespace prefix (nsl) in the nodes where are the parameters are passed. When I add them manually for example in SOAPUi it works like charm. Is there a way to add the namespace prefix without inspecting every incoming request?
Many thanks in advance!

I am a bit unsure why you have to provide the Action attribute, because SOAP operations can work without it. Perhaps there lies the clue ...?
Alternatively, if you do wish to keep it and wish to add namespace for every request then you could explore XmlDocument class and XmlNode classes. A simple code snip is here which can add namespace at a specific node -
XmlDocument xdoc = new XmlDocument();
// Get Request Xml for each of the case
xdoc.LoadXml(xmlContent);
XmlNamespaceManager nsmgr = new XmlNamespaceManager(xdoc.NameTable);
nsmgr.AddNamespace("s", "http://schemas.xmlsoap.org/soap/envelope/");
nsmgr.AddNamespace("sc", "http://tempuri.org/");

Related

How to serialize a Mtom SOAP message in WCF

Based on the following SOAP XML message how can serialize this xml to serialize and extract all elements within the ReviewCallbackMessage into a single XElement? The SOAP Message coming in is using MTom encoding. I hope someone can shed some light on this. It seems like a flaw within WCF, but maybe it's something w/ my contract settings.
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:oasis:names:tc:legalxml:wsdl:WebServicesProfile-Definitions-4.0">
<soapenv:Header/>
<soapenv:Body>
<NotifyCompleteRequestMessage xmlns="urn:oasis:names:tc:legalxml:wsdl:WebServicesProfile-Definitions-4.0">
<SendingMDELocationID xmlns="urn:oasis:names:tc:legalxml:schema:xsd:CommonTypes-4.0">
<IdentificationID xmlns="http://niem.gov/niem/niem-core/2.0"></IdentificationID>
</SendingMDELocationID>
<SendingMDEProfileCode xmlns="urn:oasis:names:tc:legalxml:schema:xsd:CommonTypes-4.0">urn:oasis:names:tc:legalxml:schema:xsd:WebServicesMessaging-2.0</SendingMDEProfileCode>
<ReviewCallbackMessage xmlns="urn:oasis:names:tc:legalxml-courtfiling:schema:xsd:ReviewFilingCallbackMessage-4.0" xmlns:nc="http://niem.gov/niem/niem-core/2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<nc:DocumentFiledDate>
<nc:DateTime>2018-06-07T13:55:56.0Z</nc:DateTime>
</nc:DocumentFiledDate>
</ReviewCallbackMessage>
</NotifyCompleteRequestMessage>
</soapenv:Body>
</soapenv:Envelope>
This is the contract method and serializing class I'm using. In reality this should load the complete body into the attribute, but it's only loading the first node SendingMDELocationID. There has to be a way to load the complete xml body into one attribute without serializing the whole xml body since if I remove the SendingMDELocationID and SendingMDEProfileCode from the envelope it gives me exactly what I need which is the ReviewCallbackMessage node + all of it's descendants.
public NotifyCompleteResponse NotifyReviewComplete(NotifyCompleteRequest request)
[System.ServiceModel.MessageContractAttribute(IsWrapped = false)]
public partial class NotifyCompleteRequest
{
[System.ServiceModel.MessageBodyMemberAttribute(Namespace = "urn:oasis:names:tc:legalxml:wsdl:WebServicesProfile-Definitions-4.0", Order = 0)]
public XElement NotifyFilingReviewCompleteRequestMessage;
public NotifyFilingReviewCompleteRequest()
{
}
}

C# SOAP response is wrong format

I have been searching the web for the last 2-3 days and remain unable to figure this one out - so now I come to you guys in the hopes that you know a solution.
I am trying to make a mocked SOAP service for a client and have made a SOAP service in visual studio. The following is the code for the SOAP action that needs to be mocked.
[WebService(Namespace = "http://mynamespace.com/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
public class MyServiceStub1 : System.Web.Services.WebService, MyServiceBindingSoap
{
[WebMethod]
[SoapDocumentMethod(Action = "http://mynamespace.com/MySoapAction",
ParameterStyle = SoapParameterStyle.Bare)]
[return: System.Xml.Serialization.XmlElementAttribute("SomeWrapperXML")]
public MyActualResponseType MyServiceRequest(
[XmlElement(ElementName = "MyRequestName")] MyServiceRequestType myServiceRequest)
{
return new MyActualResponseType();
}
And I get the following response
<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>
<SomeWrapperXML">
<MyActualResponseType>
</MyActualResponseType>
</SomeWrapperXML>
</soap:Body>
</soap:Envelope>
However, my clients expect the response to look like this
<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>
<MyActualResponseType>
</MyActualResponseType>
</soap:Body>
</soap:Envelope>
And since I cannot change the code on my clients side, I have to fix this from my side. Is there any way I can avoid getting the XML tag "SomeWrapperXML" in my response?
Setting XmlElementAttribute("") did not help and avoiding it altogether will just make it default to something else.
I have also looked at the MSDN post for altering the SOAP message, but that solution seems a bit hacky.
I ended up changing the return type of my mocked service to a field in the original return type.
In my example I needed to return the type MyActualResponseType according to the code generated by svcutil. However MyActualResponseType only contained one field/getter for a type MyActualResponse. I changed my SOAP method to this:
[WebMethod]
[SoapDocumentMethod(Action = "http://mynamespace.com/MySoapAction",
ParameterStyle = SoapParameterStyle.Bare)]
[return: System.Xml.Serialization.XmlElementAttribute("MyActualResponseType")]
public MyActualResponse MyServiceRequest(
[XmlElement(ElementName = "MyRequestName")] MyServiceRequestType myServiceRequest)
{
return new MyActualResponse();
}
Notice the [return: which makes it look like it is actually returning the type MyActualResponseType.
This solution still feels like a bit of hack, but it seems to work fine for my needs.

Service Response to WCF Includes Duplicate Namespace and Tag Prefix

Question:
Why would I receive a SOAP response fragment that contains a duplicate tag prefix namespace?
Why would I receive a different response fragment in SoapUI versus a WCF client using the exact same SOAP request?
Context:
I am calling a third-party, Java based web service with a WCF client. The SOAP fragment response sent from the third party WS contains a duplicate namespace and tag prefix for the soap envelope on the Fault tag line when calling with an incorrect value that results in a fault response. This causes the WCF to throw a CommunicationException with an innerException of XmlException which cites the following as the error:
Start element 'faultcode' from namespace '' expected. Found element 'SOAP-ENV:faultcode'
from namespace 'http://schemas.xmlsoap.org/soap/envelope/'.
This error message leads me to believe the duplicated namespace in the SOAP fragment is the culprit. The weird thing is, using the exact SOAP request sent from the WCF client to the web service in SoapUI does not result in this namespace being duplicated in the SOAP response fragment.
The WCF client is using a basicHttpBinding.
Please see below for SOAP fragments of the request, response through WCF, and response through SoapUI.
Request sent by both WCF and SoapUI:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Search xmlns="urn:ent.soap.testservice.com/objs">
<Request objType="Report">
<RequestorId>ABCD</RequestorId>
<TargetId></TargetId>
</Request>
</Search>
</s:Body>
</s:Envelope>
Response received by WCF client:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<SOAP-ENV:Fault xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:faultcode>SOAP-ENV:Server</SOAP-ENV:faultcode>
<SOAP-ENV:faultstring>Invalid action parameters</SOAP-ENV:faultstring>
<SOAP-ENV:detail>
<fns:fault xmlns:fns="urn:fault.soap.testservice.com" xmlns:java="java" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="fns:ApiFault">
<fns:exceptionCode>INTERNAL_ERROR</fns:exceptionCode>
<fns:exceptionMessage>Invalid action parameters</fns:exceptionMessage>
<fns:logDataExchangeId>1234567890</fns:logDataExchangeId>
</fns:fault>
</SOAP-ENV:detail>
</SOAP-ENV:Fault>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Response received by SoapUI:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<SOAP-ENV:Fault>
<SOAP-ENV:faultcode>SOAP-ENV:Server</SOAP-ENV:faultcode>
<SOAP-ENV:faultstring>Invalid action parameters</SOAP-ENV:faultstring>
<SOAP-ENV:detail>
<fns:fault xsi:type="fns:ApiFault" xmlns:fns="urn:fault.soap.testservice.com" xmlns:java="java" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<fns:exceptionCode>INTERNAL_ERROR</fns:exceptionCode>
<fns:exceptionMessage>Invalid action parameters</fns:exceptionMessage>
<fns:logDataExchangeId>1234567890</fns:logDataExchangeId>
</fns:fault>
</SOAP-ENV:detail>
</SOAP-ENV:Fault>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
The problem is not the duplicated namespace declaration. The problem is in this bit:
<SOAP-ENV:faultcode>SOAP-ENV:Server</SOAP-ENV:faultcode>
<SOAP-ENV:faultstring>Invalid action parameters</SOAP-ENV:faultstring>
On the SOAP Specification, the faultcode and faultstring elements are in the empty, default namespace, not in the "http://schemas.xmlsoap.org/soap/envelope/" namespace. So it really should've looked something like this:
<SOAP-ENV:Fault>
<faultcode>SOAP-ENV:MustUnderstand</faultcode>
<faultstring>SOAP Must Understand Error</faultstring>
</SOAP-ENV:Fault>
So looks like this service in particular is not being compliant with the SOAP 1.1 (or 1.2 for that matter) specification.

DocuSign Connect response is null everytime

Im trying to setup a connect listener. I am currently using a C# WCF Service that Im hosting on Azure. Im able to hit my service method but the response from docusign is null every time. In the logs, the envelope status xml has values but it is just not sent or not deserialized correctly. Im not sure what I am doing wrong and there doesnt seem to be any solid examples of a SOAP implementation anywhere. Can anyone help? The WSDL can be viewed here http://docusignconnectservice.azurewebsites.net/Service.svc?wsdl
Service Implentation
public string DocuSignConnectUpdate(DocuSignAPI.DocuSignEnvelopeInformation envelopeInformation)
{
string envelopeId = "";
if (envelopeInformation == null) return "Envelope is null";
else return envelopeInformation.EnvelopeStatus.EnvelopeID;
}
Service Contract
[ServiceContract(Namespace = "http://www.docusign.net/API/3.0")]
public interface IService
{
[OperationContract]
[XmlSerializerFormatAttribute]
string DocuSignConnectUpdate(DocuSignAPI.DocuSignEnvelopeInformation envelopeInformation);
[OperationContract]
string HelloWorld(string inputString);
DocuSign log entry
10/6/2014 1:30:12 AM Envelope Data:<?xml version="1.0" encoding="utf-8"?><DocuSignEnvelopeInformation xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.docusign.net/API/3.0"><EnvelopeStatus><RecipientStatuses><RecipientStatus><Type>Signer</Type><Email>email</Email><UserName>Username</UserName><RoutingOrder>1</RoutingOrder><Sent>2014-10-05T17:49:36.58</Sent><DeclineReason xsi:nil="true" /><Status>Sent</Status><RecipientIPAddress /><CustomFields /><AccountStatus>Active</AccountStatus><RecipientId>2a10b0ab-63f1-4df9-9258-36b97b5db120</RecipientId></RecipientStatus></RecipientStatuses><TimeGenerated>2014-10-05T18:30:09.644588</TimeGenerated><EnvelopeID>6d7692e6-3f5c-4889-914f-942b2bd83447</EnvelopeID><Subject> Signature Request on Document</Subject><UserName>Username</UserName><Email>email</Email><Status>Sent</Status><Created>2014-10-05T17:49:35.503</Created> <Sent>2014-10-05T17:49:36.613</Sent><ACStatus>Original</ACStatus><ACStatusDate>2014-10-05T17:49:35.503</ACStatusDate><ACHolder></ACHolder><ACHolderEmail></ACHolderEmail><ACHolderLocation>DocuSign</ACHolderLocation><SigningLocation>Online</SigningLocation><SenderIPAddress>ip </SenderIPAddress><EnvelopePDFHash /><CustomFields /><AutoNavigation>true</AutoNavigation><EnvelopeIdStamping>true</EnvelopeIdStamping><AuthoritativeCopy>false</AuthoritativeCopy><DocumentStatuses><DocumentStatus><ID>1</ID><Name>F_1040.pdf</Name><TemplateName /><Sequence>1</Sequence></DocumentStatus></DocumentStatuses></EnvelopeStatus></DocuSignEnvelopeInformation>
10/6/2014 1:30:12 AM Response: <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><DocuSignConnectUpdateResponse xmlns="http://www.docusign.net/API/3.0"><DocuSignConnectUpdateResult>Envelope is null</DocuSignConnectUpdateResult></DocuSignConnectUpdateResponse></s:Body> </s:Envelope>
I think there is problem with your classes for mapping of XML.
You can configure your classes with XML response you have with online tools like http://xmltocsharp.azurewebsites.net/ and use XMLSerializer to parse that XML into object .

WCF Remove xmlns:tem="http://tempuri.org/"

I have a problem getting a client to integrate with my system. I think I have narrowed the problem. The client is sending over an xml message and my system is setup to accept an xml message; however it is expecting it in certain format. The client has expressed a desire for me to setup the format on my end to accept theirs.
This is the clients message:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:tem="http://tempuri.org/">
<soapenv:Header/>
<soapenv:Body>
<NewOrder>
<Message id="d3a39c31-cc9f-4331-ad13-be74522df6eb">
<Header>
<LoginAccountIdentifier>Blank</LoginAccountIdentifier>
<LoginAccountPassword>password</LoginAccountPassword>
</Header>
I noticed that my expected format is excepting the prefix tem: on the nodes.
This is expected message:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:tem="http://tempuri.org/">
<soapenv:Header/>
<soapenv:Body>
<tem:NewOrder>
<tem:Message id="d3a39c31-cc9f-4331-ad13-be74522df6eb ">
<Header>
<LoginAccountIdentifier>Blank</LoginAccountIdentifier>
<LoginAccountPassword>password</LoginAccountPassword>
</Header>
I believe that if I can remove the prefix then this should match up the client's message with expected message. The problem is where do I remove the prefix "< tem:"; furthermore, how do I prevent this variable xmlns:tem="http://tempuri.org/" from showing up in my document?
I ran into a similar issue too long ago. Try using this:
[ServiceContract(Namespace = "")]
Apparently, the prefix is determined by the namespace so if you want it removed then this would be the way to go.
Good luck!
I'm pretty sure that's from the WebService.svc (or .asmx) class having a
[WebService(Namespace = "http://tempuri.org/")]
attribute at the top of the class definition. Removing this (or setting it to an appropriate value) should remedy the problem.

Categories

Resources