I've created a web reference to a SOAP web service in C#. If i browse to the service or use POSTMAN for example to test i get back a response as expected.
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<ns1:openResponse xmlns:ns1="http://auto.api.com/">
<return xmlns:ns2="http://auto.api.com/">
<error>User/pass incorrect</error>
</return>
</ns1:openResponse>
</soap:Body>
</soap:Envelope>
The code I am running below is quite simple, but when its connecting to the service i'm getting this error:
Unmarshalling Error: Namespace URIs and local names to the unmarshaller needs to be interned
var connect = new SOAP();
var open = connect.open(new Open
{
user = "user",
pass = "pass"
});
Any suggestions? I cant find anything that suggests how to sort it out. I've never seen this error connecting to a web service before.
Full Exception:
System.Web.Services.Protocols.SoapHeaderException: Unmarshalling Error: Namespace URIs and local names to the unmarshaller needs to be interned. at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall) at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters) at TestingConsole.web.SOAP.open(xOpen open1) in c:\Users\pm\Source\Repos\TestingConsole\Web References\web\Reference.cs:line 755 at TestingConsole.Form1.button1_Click(Object sender, EventArgs e) in c:\Users\pm\Source\Repos\TestingConsole\Form1.cs:line 32
And part of reference.cs it is referring to
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("", RequestNamespace="http://auto.api.com/", ResponseNamespace="http://auto.api.com/", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
[return: System.Xml.Serialization.XmlElementAttribute("return", Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public xOpenResponse open([System.Xml.Serialization.XmlElementAttribute("open", Form=System.Xml.Schema.XmlSchemaForm.Unqualified)] xOpen open1) {
object[] results = this.Invoke("open", new object[] {
open1});
return ((xOpenResponse)(results[0]));
}
Full exception as a service reference:
System.ServiceModel.FaultException: Unmarshalling Error: Namespace URIs and local names to the unmarshaller needs to be interned.
Server stack trace: at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc) at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout) at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs) at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation) at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
Exception rethrown at [0]: at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) at TestingConsole.SOAP.open(open request)
at TestingConsole.SOAP.TestingConsole.SOAP.open(open request) in c:\Users\pm\Source\Repos\TestingConsole\Service References\service\Reference.cs:line 7621 at TestingConsole.SOAP.open(xOpen open1) in c:\Users\pm\Source\Repos\TestingConsole\Service References\service\Reference.cs:line 7627 at TestingConsole.Form1.button1_Click(Object sender, EventArgs e) in c:\Users\pm\Source\Repos\TestingConsole\Form1.cs:line 29
And the bits from the reference.cs file its referring to:
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
TestingConsole.service.openResponse TestingConsole.service.SOAP.open(TestingConsole.service.open request) {
return base.Channel.open(request);
}
public TestingConsole.service.xOpenResponse open(TestingConsole.service.xOpen open1) {
TestingConsole.service.open inValue = new TestingConsole.service.open();
inValue.open1 = open1;
TestingConsole.service.openResponse retVal = ((TestingConsole.service.SOAP)(this)).open(inValue);
return retVal.@return;
}
2条答案
按热度按时间jaql4c8m1#
对于我来说,这是通过清空WrapperNamespace属性参数来解决的,例如:
变成
o2gm4chl2#
解决这个问题的方法是从它在Reference.cs中生成的方法中删除RequestNamespace。这意味着它向服务发送了格式正确的请求