Closed mcNets closed 3 years ago
It's not clear if the problem is WCF isn't understanding the correct response that was returned or if the error is caused by a response indicating authorization problems. Can you use fiddler to find out which is your problem and then we can go from there. Your code to add the authentication header looks correct to me so I don't think that's your problem.
Hi @mconnew.
That's the request captured by Fiddler using SoapUI:
POST http://xxx.xxx.xxx.xxx:8124/soap-generic/syracuse/collaboration/syracuse/CAdxWebServiceXmlCC HTTP/1.1
Accept-Encoding: gzip,deflate
Content-Type: text/xml;charset=UTF-8
SOAPAction: ""
Authorization: Basic V1NFUlZJ&898561NFUlZJQ0U=
Content-Length: 817
Host: xxx.xxx.xxx.xxx:8124
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.5.5 (Java/12.0.1)
<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wss="http://www.adonix.com/WSS">
<soapenv:Header/>
<soapenv:Body>
<wss:getDescription soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<callContext xsi:type="wss:CAdxCallContext">
<codeLang xsi:type="xsd:string">SPA</codeLang>
<poolAlias xsi:type="xsd:string">WDUMMY</poolAlias>
<poolId xsi:type="xsd:string">?</poolId>
<requestConfig xsi:type="xsd:string">adxwss.beautify=true</requestConfig>
</callContext>
<publicName xsi:type="xsd:string">ZPREUART</publicName>
</wss:getDescription>
</soapenv:Body>
</soapenv:Envelope>
And that using the library:
POST http://xxx.xxx.xxx.xxx:8124/soap-generic/syracuse/collaboration/syracuse/CAdxWebServiceXmlCC HTTP/1.1
Host: xxx.xxx.xxx.xxx:8124
Cache-Control: no-cache, max-age=0
Authorization: Basic V1NFUlZJ&898561NFUlZJQ0U=
SOAPAction: ""
Accept-Encoding: gzip, deflate
Content-Type: text/xml; charset=utf-8
Content-Length: 750
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<q1:getDescription xmlns:q1="http://www.adonix.com/WSS">
<callContext href="#id1"/>
<publicName xsi:type="xsd:string">ZWSSOH2</publicName>
</q1:getDescription>
<q2:CAdxCallContext id="id1" xsi:type="q2:CAdxCallContext" xmlns:q2="http://www.adonix.com/WSS">
<codeLang xsi:type="xsd:string">SPA</codeLang>
<poolAlias xsi:type="xsd:string">WDUMMY</poolAlias>
<poolId xsi:type="xsd:string"/>
<requestConfig xsi:type="xsd:string">adxwss.beautify=true</requestConfig>
</q2:CAdxCallContext>
</s:Body>
</s:Envelope>
In both cases Auth shows the same value:
Authorization Header is present: Basic V1NFUlZJ&898561NFUlZJQ0U=
Decoded Username:Password= MYUSER:MYPASS
I'm getting an exception in the proxy class:
System.NullReferenceException HResult=0x80004003 Message=Object reference not set to an instance of an object. Source=System.Private.CoreLib StackTrace: at System.Runtime.CompilerServices.CastHelpers.Unbox(Void* toTypeHnd, Object obj)
When it try to call this function:
public x3ws.getDescriptionResponse getDescription(x3ws.getDescriptionRequest request)
{
return base.Channel.getDescription(request);
}
But there is a previous error:
Error in deserializing body of reply message for operation 'getDescription'.
And that is the response using SoapUI:
HTTP/1.1 200 OK
content-type: text/xml; charset=utf-8
x-frame-options: DENY
x-content-type-options: nosniff
x-xss-protection: 1; mode=block
content-security-policy: frame-ancestors 'self';
cache-control: max-age=0, s-maxage=0, no-cache, must-revalidate, private, proxy-revalidate, no-store
pragma: no-cache
Date: Mon, 31 May 2021 09:16:26 GMT
Connection: keep-alive
Content-Length: 2966
<?xml version="1.0" encoding="utf-8"?>
<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" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wss="http://www.adonix.com/WSS">
<soapenv:Body>
<wss:getDescriptionResponse soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<getDescriptionReturn xsi:type="wss:CAdxResultXml">
<messages xsi:type="soapenc:Array" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" soapenc:arrayType="wss:CAdxMessage[0]"></messages>
<resultXml xsi:type="xsd:string">
<![CDATA[<?xml version="1.0" encoding="utf-8" ?>
<ADXDOC PNA="ZPREUART" TIM="20191023172403" PRG="ZPREUARTICLE" SPG="ZPREUARTICLE" FOL="DUMMYV11"
SOL="SAGEX3" USER="ADMIN" VER="6.30" HEAD="1" WRP="WJZPREUART"
C_SPA="Retorna el preu i dte d'un article per un client">
<ADXDATA>
<GRP PNA="GRP1" NAM="GRP1" DIM="1">
<FLD NAM="ZCPY" IDX="1" TYP="Char" PAR="Value" MOD="Input" LEN="250"/>
<FLD NAM="ZITM" IDX="2" TYP="Char" PAR="Value" MOD="Input" LEN="250"/>
<FLD NAM="ZCLI" IDX="3" TYP="Char" PAR="Value" MOD="Input" LEN="250"/>
<FLD NAM="ZFCY" IDX="4" TYP="Char" PAR="Value" MOD="Input" LEN="250"/>
<FLD NAM="ZQTY" IDX="5" TYP="Decimal" PAR="Value" MOD="Input"/>
<FLD NAM="ZDT" IDX="6" TYP="Date" PAR="Value" MOD="Input"/>
<FLD NAM="ZPREUNET" IDX="7" TYP="Decimal" PAR="Adr" MOD="Input"/>
<FLD NAM="ZDTE" IDX="8" TYP="Decimal" PAR="Adr" MOD="Input"/>
<FLD NAM="ZPREUBRUT" IDX="9" TYP="Decimal" PAR="Adr" MOD="Input"/>
<FLD NAM="ZTPROHI" IDX="10" TYP="Integer" PAR="Adr" MOD="Input"/>
</GRP>
</ADXDATA>
<ADXMEN>
</ADXMEN>
</ADXDOC>
]]>
</resultXml>
<status xsi:type="xsd:int">1</status>
<technicalInfos xsi:type="wss:CAdxTechnicalInfos">
<busy xsi:type="xsd:boolean">false</busy>
<changeLanguage xsi:type="xsd:boolean">false</changeLanguage>
<changeUserId xsi:type="xsd:boolean">false</changeUserId>
<flushAdx xsi:type="xsd:boolean">false</flushAdx>
<loadWebsDuration xsi:type="xsd:double">6</loadWebsDuration>
<nbDistributionCycle xsi:type="xsd:int">-1</nbDistributionCycle>
<poolDistribDuration xsi:type="xsd:double">0</poolDistribDuration>
<poolEntryIdx xsi:type="xsd:int">1400</poolEntryIdx>
<poolExecDuration xsi:type="xsd:double">3</poolExecDuration>
<poolRequestDuration xsi:type="xsd:double">-1</poolRequestDuration>
<poolWaitDuration xsi:type="xsd:double">0</poolWaitDuration>
<processReport xsi:type="xsd:string" xsi:nil="true"/>
<processReportSize xsi:type="xsd:int">-1</processReportSize>
<reloadWebs xsi:type="xsd:boolean">false</reloadWebs>
<resumitAfterDBOpen xsi:type="xsd:boolean">false</resumitAfterDBOpen>
<rowInDistribStack xsi:type="xsd:int" xsi:nil="true"/>
<totalDuration xsi:type="xsd:double">12</totalDuration>
<traceRequest xsi:type="xsd:string"/>
<traceRequestSize xsi:type="xsd:int">0</traceRequestSize>
</technicalInfos>
</getDescriptionReturn>
</wss:getDescriptionResponse>
</soapenv:Body>
</soapenv:Envelope>
And that the response using the library:
<?xml version="1.0" encoding="utf-8"?>
<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" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wss="http://www.adonix.com/WSS">
<soapenv:Body>
<wss:getDescriptionResponse soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<getDescriptionReturn xsi:type="wss:CAdxResultXml">
<messages xsi:type="soapenc:Array" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" soapenc:arrayType="wss:CAdxMessage[0]"></messages>
<resultXml xsi:type="xsd:string">
<![CDATA[<?xml version="1.0" encoding="utf-8" ?>
<ADXDOC PNA="ZPREUART" TIM="20191023172403" PRG="ZPREUARTICLE" SPG="ZPREUARTICLE" FOL="DUMMYV11"
SOL="SAGEX3" USER="ADMIN" VER="6.30" HEAD="1" WRP="WJZPREUART"
C_SPA="Retorna el preu i dte d'un article per un client">
<ADXDATA>
<GRP PNA="GRP1" NAM="GRP1" DIM="1">
<FLD NAM="ZCPY" IDX="1" TYP="Char" PAR="Value" MOD="Input" LEN="250"/>
<FLD NAM="ZITM" IDX="2" TYP="Char" PAR="Value" MOD="Input" LEN="250"/>
<FLD NAM="ZCLI" IDX="3" TYP="Char" PAR="Value" MOD="Input" LEN="250"/>
<FLD NAM="ZFCY" IDX="4" TYP="Char" PAR="Value" MOD="Input" LEN="250"/>
<FLD NAM="ZQTY" IDX="5" TYP="Decimal" PAR="Value" MOD="Input"/>
<FLD NAM="ZDT" IDX="6" TYP="Date" PAR="Value" MOD="Input"/>
<FLD NAM="ZPREUNET" IDX="7" TYP="Decimal" PAR="Adr" MOD="Input"/>
<FLD NAM="ZDTE" IDX="8" TYP="Decimal" PAR="Adr" MOD="Input"/>
<FLD NAM="ZPREUBRUT" IDX="9" TYP="Decimal" PAR="Adr" MOD="Input"/>
<FLD NAM="ZTPROHI" IDX="10" TYP="Integer" PAR="Adr" MOD="Input"/>
</GRP>
</ADXDATA>
<ADXMEN>
</ADXMEN>
</ADXDOC>
]]>
</resultXml>
<status xsi:type="xsd:int">1</status>
<technicalInfos xsi:type="wss:CAdxTechnicalInfos">
<busy xsi:type="xsd:boolean">false</busy>
<changeLanguage xsi:type="xsd:boolean">false</changeLanguage>
<changeUserId xsi:type="xsd:boolean">false</changeUserId>
<flushAdx xsi:type="xsd:boolean">false</flushAdx>
<loadWebsDuration xsi:type="xsd:double">5</loadWebsDuration>
<nbDistributionCycle xsi:type="xsd:int">-1</nbDistributionCycle>
<poolDistribDuration xsi:type="xsd:double">0</poolDistribDuration>
<poolEntryIdx xsi:type="xsd:int">10268</poolEntryIdx>
<poolExecDuration xsi:type="xsd:double">3</poolExecDuration>
<poolRequestDuration xsi:type="xsd:double">-1</poolRequestDuration>
<poolWaitDuration xsi:type="xsd:double">0</poolWaitDuration>
<processReport xsi:type="xsd:string" xsi:nil="true"/>
<processReportSize xsi:type="xsd:int">-1</processReportSize>
<reloadWebs xsi:type="xsd:boolean">false</reloadWebs>
<resumitAfterDBOpen xsi:type="xsd:boolean">false</resumitAfterDBOpen>
<rowInDistribStack xsi:type="xsd:int" xsi:nil="true"/>
<totalDuration xsi:type="xsd:double">11</totalDuration>
<traceRequest xsi:type="xsd:string"/>
<traceRequestSize xsi:type="xsd:int">0</traceRequestSize>
</technicalInfos>
</getDescriptionReturn>
</wss:getDescriptionResponse>
</soapenv:Body>
</soapenv:Envelope>
In both cases it is a valid response.
Thanks for your help.
in .net5 code I get an exception accessing client.InnerChannel (in your example OperationContextScope(this.x3_ws.InnerChannel)). Were you able to get this going? I'm trying to add an Authorization header with "Bearer mytoken"
in .net5 code I get an exception accessing client.InnerChannel (in your example OperationContextScope(this.x3_ws.InnerChannel)). Were you able to get this going? I'm trying to add an Authorization header with "Bearer mytoken"
@jjakob666 yes it woks fine in net5 and netcoreapp3.1
I worked out the problem. This shouldn't have worked in .NET Framwork either, unless someone modified the code generated by Add Service Reference or svcutil. The problem is an error in your WSDL. If you look at the response, the XML element technicalInfos
has a child element called rowInDistribStack
. This is the XML in the response:
<rowInDistribStack xsi:type="xsd:int" xsi:nil="true"/>
You can see there's no value for it, and it specified xsi:nil="true"
, which means it's not a missing value, it's explicitly there but is null. If you look at the WSDL, the schema definition for the complexType CAdxTechnicalInfos
looks like this:
<complexType name="CAdxTechnicalInfos">
<sequence>
<element name="busy" type="xsd:boolean"/>
<element name="changeLanguage" type="xsd:boolean"/>
<element name="changeUserId" type="xsd:boolean"/>
<element name="flushAdx" type="xsd:boolean"/>
<element name="loadWebsDuration" type="xsd:double"/>
<element name="nbDistributionCycle" type="xsd:int"/>
<element name="poolDistribDuration" type="xsd:double"/>
<element name="poolEntryIdx" type="xsd:int"/>
<element name="poolExecDuration" type="xsd:double"/>
<element name="poolRequestDuration" type="xsd:double"/>
<element name="poolWaitDuration" type="xsd:double"/>
<element name="processReport" nillable="true" type="xsd:string"/>
<element name="processReportSize" type="xsd:int"/>
<element name="reloadWebs" type="xsd:boolean"/>
<element name="resumitAfterDBOpen" type="xsd:boolean"/>
<element name="rowInDistribStack" type="xsd:int"/>
<element name="totalDuration" type="xsd:double"/>
<element name="traceRequest" nillable="true" type="xsd:string"/>
<element name="traceRequestSize" type="xsd:int"/>
</sequence>
</complexType>
There are a couple of elements with the attribute nillable="true"
, e.g. traceRequest. Without this attribute, the element isn't allowed to be nil. The element rowInDistribStack
doesn't specify nillable="true"
which means it's not allowed to specify xsi:nil="true"
in the response document, but it does. You need to fix your WSDL and regenerate your client. This is what that line should look like:
<element name="rowInDistribStack" nillable="true" type="xsd:int"/>
When you generate the WCF proxy client, you will get a property which looks something like this:
[System.Xml.Serialization.SoapElementAttribute(IsNullable=true)]
public System.Nullable<int> rowInDistribStack {
get {
return this.rowInDistribStackField;
}
set {
this.rowInDistribStackField = value;
this.RaisePropertyChanged("rowInDistribStack");
}
}
This sets the IsNullable
property on the SoapElement
attribute to true, and also uses Nullable<int>
as the data type. This provides you a nullable property where you can tell the difference between xsi:nil="true"
or the value being absent (which would have previously left the value as 0, but is now going to be null
), and the value 0 being provided.
Thanks @mconnew
Let me try to manually modify the WSDL file that is generated by a 3rd party software.
I took a look at WSDL generated in .Net Framework and it has same definition:
<xsd:element name="rowInDistribStack" type="xsd:int" />
But it works without any modification.
Again thanks for your time.
I tested generating a client from the wall on .NET Framework and got the same exception as you are seeing on core. There isn't a behavior difference between NetFx and Core here. This is why I suggested that maybe someone previously edited the generated code in your NetFx app. It's only going to throw an exception if there's a nil value in the response. An integer value won't cause the exception.
@mconnew Hi.
I've manually modified the WSDL file and then I've generated a new proxy class using this file and it works!
Thanks for your help.
Visual Studio 16.9.5
I'm trying to migrate our client classes from Net Framework 4.7.2 to Net 5 and I'm getting an error:
Error in deserializing body of reply message for operation 'read'.
I'm trying to connect to a 3rd party web service that requires pre-authentication, I'm using OperationContextScope to set it.
This is the payload returned using SoapUI:
I'm trying to add the library source code to my project instead of Nuget package, but I'm getting some compiler errors, I think because I don't have all frameworks installed.
And this is WDSL content: