I'm trying to run GetChanges method (sitedata.asmx) from a Java application. However I can't figure out the correct parameters I must pass. This is for SharePoint 2010.
By checking on the service protocol specification, I saw this are the required parameters:
objectType: The change tracking space
to report about, either
"ContentDatabase" or "SiteCollection".
All other objectType values, as
defined in section 2.2.5.3, MUST NOT
be used. Note that "Site" in the
context of this parameter actually
means site collection.
contentDatabaseId: GUID of the content
database, known in advance or obtained
by GetContent request.
LastChangeId: A token specifying the starting point
for the requested change report.
Normally the protocol client obtains
this value from the response to a
previous GetContent or GetChanges operation.
CurrentChangeId: A token specifying
the endpoint for the requested change
report. If not empty, CurrentChangeId
must be a valid token obtained from
the response to a previous GetChanges
operation. Normally, this element is
empty; empty specifies that the
protocol client requests all changes
starting from the starting point up to
the present time.
Timeout: A value
that determines how many changes
should be fetched in the current
operation. This value MUST be greater
than 0 and the protocol server MUST
only fetch x% of total changes that
are fetched by default, where x is
(Timeout divided by 30000).
The protocol client MUST pass tokens that
correspond to the change tracking
space specified by the objectType and
the target URL of the SOAP request.
The SOAP In message I'm sending is as follows:
<?xml version='1.0' encoding='UTF-8'?>
<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
<soapenv:Body>
<ns1:GetChanges xmlns:ns1="http://schemas.microsoft.com/sharepoint/soap/">
<ns1:objectType>SiteCollection</ns1:objectType>
<ns1:contentDatabaseId>E5C5E20A-5A9F-406C-B9F6-28923750CECD</ns1:contentDatabaseId>
<ns1:startChangeId>1;0;E5C5E20A-5A9F-406C-B9F6-28923750CECD;634438121498470000;46852</ns1:startChangeId>
<ns1:Timeout>0</ns1:Timeout>
</ns1:GetChanges>
</soapenv:Body>
</soapenv:Envelope>
However I get this response:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<soap:Fault>
<soap:Code>
<soap:Value>soap:Receiver</soap:Value>
</soap:Code>
<soap:Reason>
<soap:Text xml:lang="en">Exception of type 'Microsoft.SharePoint.SoapServer.SoapServerException' was thrown.</soap:Text>
</soap:Reason>
<detail>
<errorstring xmlns="http://schemas.microsoft.com/sharepoint/soap/">Object reference not set to an instance of an object.</errorstring>
</detail>
</soap:Fault>
</soap:Body>
</soap:Envelope>
Checked the logs from SharePoint (located at Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\LOGS) and found the following exception:
SOAP exception: System.NullReferenceException: Object reference not set to an instance of an object.
at Microsoft.SharePoint.SPChangeToken.ParseChangeToken(String strChangeToken)
at Microsoft.SharePoint.SPChangeToken..ctor(String strChangeToken)
at Microsoft.SharePoint.SoapServer.SiteDataImpl.GetChanges(ObjectType objectType, String contentDatabaseId, String& startChangeId, String& endChangeId, Int64 maxChangesToFetch, UInt32 maxSPRequests, Boolean getMetadata, Boolean ignoreSecurityIfInherit, Int32 schemaVersion, Boolean& moreChanges)
at Microsoft.SharePoint.SoapServer.SiteDataImpl.GetChanges(ObjectType objectType, String contentDatabaseId, String& startChangeId, String& endChangeId, Int32 Timeout, Boolean& moreChanges)
at Microsoft.SharePoint.SoapServer.SiteData.GetChanges(ObjectType objectType, String contentDatabaseId, String& LastChangeId, String& CurrentChangeId, Int32 Timeout, Boolean& moreChanges)
However, I'm not able to find any references to that error. I can't even found the method ParseChangeToken from SPChangeToken class (http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spchangetoken_methods.aspx), so this is confusing.
I already saw this question, however this doesn't solve my issue: Other question
Can anyone help me calling this web service correctly?
EDIT
Tried calling it from a C# application to determine that the issue is not with Java. This is the code:
SiteData.SiteDataSoapClient siteDataService = new SiteData.SiteDataSoapClient();
siteDataService.Endpoint.Address = new System.ServiceModel.EndpointAddress("URL/_vti_bin/sitedata.asmx");
siteDataService.ClientCredentials.Windows.ClientCredential = new System.Net.NetworkCredential("username", "password", "domain");
siteDataService.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;
String startChangeId = "1;1;69d025ce-96a7-4131-adc0-7da1603e8d24;634439002539570000;46914";
String endChangeId = "";
bool hasMoreChanges = false;
String databaseID = E5C5E20A-5A9F-406C-B9F6-28923750CECD; //Got it by querying SharePoint database. Any idea how to get it programatically?
String result = siteDataService.GetChanges(SiteData.ObjectType.SiteCollection, databaseID, ref startChangeId, ref endChangeId, 0, out hasMoreChanges);
return result;
However, I got 'Microsoft.SharePoint.SoapServer.SoapServerException' and the detail of this exception is null. Used Fiddler to spy on the XML returned by the SharePoint server, and found the same 'Object reference not set to an instance of an object' exception.
So this certainly means there is something wrong with the parameters I'm passing, right?
Thanks!!
Edit
If someone is interested, I made this work too by setting StartChangeId to LastChangeId and EndChangeId to CurrentChangeId in the XML message.
Solved it. By checking on the SharePoint logs, I noticed the following lines:
06/20/2011 08:24:03.80 w3wp.exe (0x1C2C) 0x0CAC SharePoint Foundation General fbs6 Medium <?xml version="1.0" ?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:Body><GetChanges xmlns="http://schemas.microsoft.com/sharepoint/soap/"><objectType>SiteCollection</objectType><contentDatabaseId>{E5C5E20X-5A9F-406C-B9F6-28923750CECD}</contentDatabaseId><startChangeId></startChangeId><endChangeId>1;1;69c025ce-96a7-4131-adc0-7da1603e8d24;634439772069030000;47449</endChangeId><Timeout>0</Timeout></GetChanges></S:Body></S:Envelope> bafe1d43-e41c-47e9-bff2-5dc35a15298d
06/20/2011 08:24:03.80 w3wp.exe (0x1C2C) 0x0CAC SharePoint Foundation General 9ka5 Verbose GetChanges: objectType=SiteCollection, contentDbId={E5C5E20X-5A9F-406C-B9F6-28923750CECD}, startChange=, endChange=; MaxChanges=0, MaxSPRequests=50 bafe1d43-e41c-47e9-bff2-3dc35a15298d
Notice on the second line, that the content database Id is enclosed by "{}" characters. Also, see that "contentDbId" is parsed correctly from the incoming XML, while "endChange" is empty. This second observation, is probably what leads to the "Object reference not set to an instance of an object" exception. So, what is wrong with that changeId? No idea, probably there is something wrong with the XML encoding that prevents SharePoint from parsing the changeId correctly.
By further looking on the same log, I found this lines:
06/20/2011 08:42:54.35 w3wp.exe (0x1C2C) 0x2BC4 SharePoint Foundation General fbs6 Medium <?xml version='1.0' encoding='UTF-8'?><soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope"><soapenv:Body><ns1:GetChangesEx xmlns:ns1="http://schemas.microsoft.com/sharepoint/soap/"><ns1:version>1</ns1:version><ns1:xmlInput><GetChanges><ObjectType>1</ObjectType><ContentDatabaseId>{x4284f47-f050-4fe9-b7e9-caf8f4b882b0}</ContentDatabaseId><StartChangeId>1;0;x4284f47-f050-4fe9-b7e9-caf8f4b882b0;634441572386370000;72973</StartChangeId><EndChangeId /><RequestLoad>100</RequestLoad><GetMetadata>False</GetMetadata><IgnoreSecurityIfInherit>True</IgnoreSecurityIfInherit></GetChanges></ns1:xmlInput></ns1:GetChangesEx></soapenv:Body></soapenv:Envelope> fa5ab5a7-2e27-4e78-aa1f-b027ca3b120f
06/20/2011 08:42:54.35 w3wp.exe (0x1C2C) 0x2BC4 SharePoint Foundation General 9ka5 Verbose GetChanges: objectType=ContentDatabase, contentDbId={x4284f47-f050-4fe9-b7e9-caf8f4b882b0}, startChange=1;0;x4284f47-f050-4fe9-b7e9-caf8f4b882b0;634441572386370000;72973, endChange=; MaxChanges=500, MaxSPRequests=50 fa5ab5b7-2e27-4e78-aa1f-b027ca3b120f
Here, the changeId is correctly parsed from the incoming XML. So, I changed from GetChanges() method to GetChangesEx(), passed the exact same parameters I was using on the former call, and it worked correctly!! My guess is that because the parameters are encoded inside an element of the SOAP In request, the Web Service is able to parse them correctly.
Here is the final SOAP In message (formatted):
<?xml version='1.0' encoding='UTF-8'?>
<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
<soapenv:Body>
<ns1:GetChangesEx xmlns:ns1="http://schemas.microsoft.com/sharepoint/soap/">
<ns1:version>1</ns1:version>
<ns1:xmlInput><GetChanges><ObjectType>7</ObjectType><ContentDatabaseId>{X5C5E20A-5A9F-406C-B9F6-28923750CECD}</ContentDatabaseId><StartChangeId>1;1;69f025ce-96a7-4131-adc0-7da1603e8d24;634439727021700000;47404</StartChangeId><EndChangeId>1;1;69d025ce-96a7-4131-adc0-7da1603e8b24;634441802456970000;47472</EndChangeId><RequestLoad>100</RequestLoad><GetMetadata>False</GetMetadata><IgnoreSecurityIfInherit>True</IgnoreSecurityIfInherit></GetChanges></ns1:xmlInput>
</ns1:GetChangesEx>
</soapenv:Body>
</soapenv:Envelope>
Edit
C# code example:
SiteData.SiteDataSoapClient siteDataService = new SiteData.SiteDataSoapClient();
siteDataService.Endpoint.Address = new System.ServiceModel.EndpointAddress("URL/_vti_bin/sitedata.asmx");
siteDataService.ClientCredentials.Windows.ClientCredential = new System.Net.NetworkCredential("username", "password", "domain");
siteDataService.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;
String xmlInput = "<GetChanges>" +
"<ObjectType>7</ObjectType>" +
"<ContentDatabaseId>{X5C5E20A-5A9F-406C-B9F6-28923750CECD}</ContentDatabaseId>" +
"<StartChangeId>1;1;69b025ce-96a7-4131-adc0-7da1603e8d24;634439727021700000;47404</StartChangeId>" +
"<EndChangeId>1;1;69b025ce-96a7-4131-adc0-7da1603e8d24;634441802456970000;47472</EndChangeId>" +
"<RequestLoad>100</RequestLoad>" +
"<GetMetadata>False</GetMetadata>" +
"<IgnoreSecurityIfInherit>True</IgnoreSecurityIfInherit>" +
"</GetChanges>";
String result = siteDataService.GetChangesEx(1, xmlInput);
Related
Due to requirements from a web service that I have no control over, I need to change my ns prefixes from the defaults of "s" and "h". The service provider has provided a .wsdl file for my service reference, however, they do not appear to have an online wsdl for metadata exchange. I have emailed them and they confirmed that the prefixes have to be specific values (right or wrong on their part, I have to make this work).
Can someone please tell me the easiest way to change these values? Is there something I can modify in Reference.cs? Do I have to implement some sort of message formatting logic into my requests to change the values just prior to sending out the request?
Every element in the XML has to have a prefix of a specific value (2 values total), or the WS will not accept the request and simply returns HTML in the response. When I copy the request captured in Fiddler, over to SOAP UI and update the prefixes to what they require, the request works fine when executed from Soap UI. I'm simply not finding any simple solutions to this seemingly simple problem for c# VS 2017 development platform.
Also worth noting, when I load the .wsdl file into Soap UI, Soap UI generates all of the ws operations and requests with the correct, desired prefixes that I need in my c# app. How does Soap UI know the exact prefixes to generate in the requests?
I need to modify this:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
<h:FooListHeader xmlns:h="http://foo.foo.com/Hello" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<h:FooList>
<h:FooStatement>
<h:Title>Foo</h:Title>
<h:Value>123</h:Value>
</h:FooStatement>
</h:FooList>
</h:FooListHeader>
</s:Header>
<s:Body>
<GetFooRequestType xmlns="http://foo.foo.com/Hello">
<MessageRequest xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<ConFooRequest/>
</MessageRequest>
</GetFooRequestType>
</s:Body>
</s:Envelope>
To something like this:
<soapenv:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:foo="http://foo.foo.com/Hello">
<soapenv:Header>
<foo:FooListHeader xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<foo:FooList>
<foo:FooStatement>
<foo:Title>Foo</foo:Title>
<foo:Value>123</foo:Value>
</foo:FooStatement>
</foo:FooList>
</foo:FooListHeader>
</soapenv:Header>
<soapenv:Body>
<foo:GetFooRequestType xmlns="http://foo.foo.com/Hello">
<foo:MessageRequest xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<foo:ConFooRequest/>
</foo:MessageRequest>
</foo:GetFooRequestType>
</soapenv:Body>
</soapenv:Envelope>
Example c# code:
public GetYaddaYaddaResponseType CheckConnection()
{
Yadda client = new Yadda();
var msgRequest = new GetYaddaYaddaResponseType { ConnectionConfirmationRequest = new ConfirmConnectRequestType() };
List<Statement> statementList = new List<Statement>
{
new Statement { Name = "Yo", Value = "123" },
new Statement { Name = "Hey", Value = "123" },
};
var header = new StatementHeader
{
StatementList = statementList.ToArray()
};
var response = client.GetYaddaYaddaMessage(ref header, msgRequest);
return response;
}
I have C# code to produce a SAML 2.0 AuthnRequest:
String requestXML = "<samlp:AuthnRequest xmlns:samlp=\"urn:oasis:names:tc:SAML:2.0:protocol\" xmlns:saml=\"urn:oasis:names:tc:SAML:2.0:assertion\" ID=\"https://saml.example.com/login\" Version=\"2.0\" IssueInstant=\"" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + "\" AssertionConsumerServiceIndex=\"0\"><saml:Issuer>https://saml.example.com/login</saml:Issuer><samlp:NameIDPolicy AllowCreate=\"true\" Format=\"urn:oasis:names:tc:SAML:2.0:nameid-format:transient\"/></samlp:AuthnRequest>";
String convertedRequestXML = System.Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(requestXML));
return Redirect("https://idp.ssocircle.com:443/sso/SSORedirect/metaAlias/ssocircle"+ "?SAMLRequest=" + convertedRequestXML + "&RelayState=" + HttpUtility.UrlEncode("/SamlLogin?ReturnUrl=" + returnurl));
With my actual domain name instead of example.com. I set this up on https://ssocircle.com/ with the SP metadata like this
<md:EntityDescriptor
xmlns:md="urn:oasis:names:tc:SAML:2.0:metadata"
xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion"
entityID="https://saml.example.com/login">
<md:SPSSODescriptor
protocolSupportEnumeration="urn:oasis:names:tc:SAML:2.0:protocol">
<md:AssertionConsumerService index="0"
Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST"
Location="https://saml.example.com/login" />
</md:SPSSODescriptor>
<md:Organization>
<md:OrganizationName xml:lang="en">
example
</md:OrganizationName>
<md:OrganizationDisplayName xml:lang="en">
example
</md:OrganizationDisplayName>
<md:OrganizationURL xml:lang="en">
http://www.example.com/
</md:OrganizationURL>
</md:Organization>
However, the page returns with:
Error occurred
Reason: The SAML Request is invalid.
And unhelpfully, no other errors. I have also tried setting this up with https://openidp.feide.no but that only returned a blank page with a 500 server error.
My get string comes out as
https://idp.ssocircle.com/sso/SSORedirect/metaAlias/ssocircle?SAMLRequest=PHNhbWxwOkF1dGhuUmVxdWVzdCB4bWxuczpzYW1scD0idXJuOm9hc2lzOm5hbWVzOnRjOlNBTUw6Mi4wOnByb3RvY29sIiB4bWxuczpzYW1sPSJ1cm46b2FzaXM6bmFtZXM6dGM6U0FNTDoyLjA6YXNzZXJ0aW9uIiBJRD0iaHR0cHM6Ly9zYW1sLmV4YW1wbGUuY29tL2xvZ2luIiBWZXJzaW9uPSIyLjAiIElzc3VlSW5zdGFudD0iMjAxNC0wOS0xMVQwOTozMTo1NyIgQXNzZXJ0aW9uQ29uc3VtZXJTZXJ2aWNlSW5kZXg9IjAiPjxzYW1sOklzc3Vlcj5odHRwczovL3NhbWwuZXhhbXBsZS5jb20vbG9naW48L3NhbWw6SXNzdWVyPjxzYW1scDpOYW1lSURQb2xpY3kgQWxsb3dDcmVhdGU9InRydWUiIEZvcm1hdD0idXJuOm9hc2lzOm5hbWVzOnRjOlNBTUw6Mi4wOm5hbWVpZC1mb3JtYXQ6dHJhbnNpZW50Ii8+PC9zYW1scDpBdXRoblJlcXVlc3Q+&RelayState=%2fSamlLogin%3fReturnUrl%3d31lOpEvtWshJNDa314yOgw%3d%3d
Which https://idp.ssocircle.com/sso/toolbox/samlDecode.jsp is 'unable to decode' and https://rnd.feide.no/simplesaml/module.php/saml2debug/debug.php comes out with
<samlp:AuthnRequest xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol" xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" ID="https://saml.example.com/login" Version="2.0" IssueInstant="2014-09-11T09:31:57" AssertionConsumerServiceIndex="0"><saml:Issuer>https://saml.example.com/login</saml:Issuer><samlp:NameIDPolicy AllowCreate="true" Format="urn:oasis:names:tc:SAML:2.0:nameid-format:transient"/��[[�]]��\]Y\�
I have also tried with similar results
String convertedRequestXML = System.Convert.ToBase64String(System.Text.UTF8Encoding.UTF8.GetBytes(requestXML));
My questions are
1) Is my SAML AuthnRequest actually valid?
2) Is my encoding method correct?
3) Are there any better tools I can use to debug this? These sites do not give out any helpful (or any at all) error messages when something goes wrong
It's not enough to Base64 encode the request, you also need to do something called deflating.
Read the chapter on the HTTP redirect binding.
There is a explanation on how to defalte in C# here
well i wanted to make a simple webservice that searches the db and return the data i know i can do it with mysql connector but this is just to learn how to use soaps here is the code for php soap server
require_once ('lib/nusoap.php');
$namespace = "http://localhost/webservice/index.php?wsdl";
$server = new soap_server();
$server->configureWSDL("DBQuery");
$server->wsdl->schemaTargetNamespace = $namespace;
$server->register(
'QueryMsg',
array('name'=>'xsd:string'),
array('return'=>'xsd:string'),
$namespace,
false,
'rpc',
'encoded',
'returns data from database');
function QueryMsg($query)
{
$con=mysqli_connect('localhost','root','','webserivce');
if (mysqli_connect_errno()) {
return "Failed to connect to MySQL: " . mysqli_connect_error();
}
if(!isset($query) or strpos(strtolower($query),'select')<=-1)
{
return "invalid order";
}
else
{
mysqli_real_escape_string($con,$query);
$result = mysqli_query($con,$query);
while($row = mysqli_fetch_array($result)) {
$data[] = $row;}
return json_encode($data);
}
}
// create HTTP listener
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
$server->service($HTTP_RAW_POST_DATA);
exit();
?>
it works when i try calling it from a php soap client but when i try adding this http:// localhost /webservice/index.php in visual studio as service refernce to consume it from C# application i get an error here it is
The HTML document does not contain Web service discovery information.
Metadata contains a reference that cannot be resolved: 'http://localhost/webservice/index.php'.
The content type text/xml; charset=ISO-8859-1 of the response message does not match the content type of the binding (application/soap+xml; charset=utf-8). If using a custom encoder, be sure that the IsContentTypeSupported method is implemented properly. The first 700 bytes of the response were: '<?xml version="1.0" encoding="ISO-8859-1"?><SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body><SOAP-ENV:Fault><faultcode xsi:type="xsd:string">SOAP-ENV:Client</faultcode><faultactor xsi:type="xsd:string"></faultactor><faultstring xsi:type="xsd:string">Operation '' is not defined in the WSDL for this service</faultstring><detail xsi:type="xsd:string"></detail></SOAP-ENV:Fault></SOAP-ENV:Body></SOAP-ENV:Envelope>'.
The remote server returned an error: (500) Internal Server Error.
If the service is defined in the current solution, try building the solution and adding the service reference again.
solved : well it was easy actually there is two ways either use WCF and change encoding to ISO-8859-1
or change encoding of the web service itself by adding this line $server->soap_defencoding = 'UTF-8'; after creating the soap server
I would try adding the service WSDL with a tool like SOAP U.I. and see what kind of errors you get back from that. It's a little more agnostic than adding a web reference with C#, and might disclose more details about why at the client level you can't consume this.
I'm happy to help you troubleshoot this with a little more information. Are you running this service on the same machine where you're running the client from? If it's complaining about being unable to correlate the file http://localhost/webservice/index.php to something I wonder if the discovery process is trying to evaluate a file that can't be found. I.E. an import operation in your source WSDL that points to a URL the client can't resolve.
We have been battling with a SOAP related problem for some time. We have a SOAP based API that can be called from a number of languages (PHP, Ruby etc). C#, however, seems to choke in certain circumstances.
Unfortunately, it is not clear to us why it dies. We are not C# people, but we did get an external, C# person to look at the problem. And, they were also baffled!
The wdsl can be seen here: http://sandbox.knowledgetree.com/ktwebservice/webservice.php?wsdl (yes, its large).
From C#, session creation, and several other calls work happily. However, the get_folder_contents call fails. The call executes, and fiddler shows valid XML being returned. However, C#'s return value is null.
The request, per Fiddler, is as follows:
<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">
<s:get_folder_contents>
<session_id xsi:type="xsd:string">or8llmjj5rm7co9h5p2k762s77</session_id>
<folder_id xsi:type="xsd:int">99</folder_id>
<depth xsi:type="xsd:int">1</depth>
<what xsi:type="xsd:string">DFS</what>
</s:get_folder_contents>
</s:Body>
</s:Envelope>
(I've added spaces and line breaks to the fiddler logs).
The response, per Fiddler (but, again, formatted for clairty), is as follows:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns4="urn:KnowledgeTree" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<SOAP-ENV:get_folder_contentsResponse>
<item xsi:type="ns4:kt_folder_contents">
<status_code xsi:type="xsd:int">0</status_code>
<message xsi:type="xsd:string"></message>
<folder_id xsi:type="xsd:int">99</folder_id>
<folder_name xsi:type="xsd:string">Nic</folder_name>
<full_path xsi:type="xsd:string">Nic</full_path>
<items xsi:type="SOAP-ENC:Array" SOAP-ENC:arrayType="ns4:kt_folder_item[0]" xsi:nil="true"/>
</item>
</SOAP-ENV:get_folder_contentsResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
The (crude) C# application we used to test is as follows:
public partial class Form1 : Form
{
private string _sessionId;
private KnowledgeTreePortClient _webService;
public Form1()
{
InitializeComponent();
_webService = new KnowledgeTreePortClient();
_webService.loginCompleted += new EventHandler<loginCompletedEventArgs>(WebLoginCompleted);
_webService.loginAsync("username", "secret_password", "nil", "c-sharp-test");
}
private void WebLoginCompleted(object sender, loginCompletedEventArgs e)
{
_sessionId = e.Result.message;
_webService.get_folder_contentsCompleted += GetFolderComplete;
_webService.get_folder_contentsAsync(_sessionId, 99,1, "DFS");
}
private void GetFolderComplete(object sender, get_folder_contentsCompletedEventArgs e)
{
}
}
I'd prefer to fix this from the client (C#) side. But, any guidance as to what we are doing wrong would be much appreciated!
renen.
I tried it and got the same response.
The way I resolved it and got the response you're looking for is by adding a web reference instead. To do this right click on the references folder of your project, select add service service reference, click on the web reference button on the bottom and then proceed from there.
The proxy classes generated by that method behave as you'd expect.
As to why the service reference is not working I'm still looking into that....
EDIT:
So I've check the response Xml against the WSDL and I cannot spot any namespace mismatches. I found a couple of articles detailing how to resolve sub elements (like arrays) being null which was mostly because of a namespace mismatch - but in your case the whole kt_folder_contents value is bull and as far as I can see the namespace (urn:KnowledgeTree) in the generated wrappers is correct.
I hope someone else can give a fix for this - else if the Web Reference generated proxy works for you...
Not sure whether this makes a difference in view of the comments regarding true root cause but I have found that C#/VS interprets the entire return value as null when there is an array within the SOAP response that contains a xsi:nil="true"/> value as in:
items xsi:type="SOAP-ENC:Array" SOAP-ENC:arrayType="ns4:kt_folder_item[0]" xsi:nil="true"/>
I am trying to consume the webservice in a WINFORMS application and responses without this array value seem to work fine but the two that show null return values in their response object both have the nil="true" for an array that is part of the object. Don't know if it's merely coincidence but appears to be related to comment on profile (WS-I BP1) compliance?
Alan
I came across this problem and the Web Reference proxy workaround that #QuintonBernhardt suggested worked for me. Just want to mention how to add Web Reference in recent Visual Studio versions (2017+):
In regular add service reference dialog, choose "Advanced"
Then in the compatibility section select "Add Web Reference"
I have a problem in my C# ASP.NET MVC web app where we are trying to add multiple references to different versions of the Magento API.
Basically my app needs to be able to connect to different Magento ecommerce stores. Some of these stores could be version 1.4, some could be 1.5 and so on. To handle this situation I have added multiple web references, one for each of the versions:
<applicationSettings>
<WebApp.Properties.Settings>
<setting name="WebApp_MagentoWebReference_MagentoService"
serializeAs="String">
<value>http://example.com/magento1411/index.php/api/v2_soap/index/</value>
</setting>
<setting name="WebApp_Magento1510WebReference_MagentoService"
serializeAs="String">
<value>http://example.com/magento1510/index.php/api/v2_soap/index/</value>
</setting>
</WebApp.Properties.Settings>
</applicationSettings>
And then in the code I make sure to create an instance using the right web reference that matches the version I am targeting:
string url = "http://example.com/magento1411/index.php/api/v2_soap/";
_magentoService = new MagentoWebReference.MagentoService();
_magentoService.Url = url;
string apiUser = "user";
string apiKey = "key";
sessionId = _magentoService.login(apiUser, apiKey);
var magentoProductList = _magentoService.catalogProductList(sessionId, null, null);
You can see that I am deliberately creating the version 1.4 web reference when requesting the product list from a version 1.4 shop. However when this code runs it fails with this error:
Cannot assign object of type WebApp.Magento1510WebReference.salesOrderInvoiceEntity[]
to an object of type WebApp.MagentoWebReference.salesOrderInvoiceEntity[].
For some reason the return value is of type Magento1510WebReference.salesOrderInvoiceEntity.
Is there any known problem adding multiple web references like this? Is Visual Studio or IIS getting confused between the two references?
This is the full stack trace:
System.Exception: There was a problem recieving a list of invoices from mageto store: http://example.com ---> System.InvalidOperationException: There is an error in XML document (2, 485). ---> System.InvalidCastException: Cannot assign object of type WebApp.Magento1510WebReference.salesOrderInvoiceEntity[] to an object of type WebApp.MagentoWebReference.salesOrderInvoiceEntity[].
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReader1.Read351_salesOrderInvoiceListResponse()
at Microsoft.Xml.Serialization.GeneratedAssembly.ArrayOfObjectSerializer469.Deserialize(XmlSerializationReader reader)
at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events)
--- End of inner exception stack trace ---
at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events)
at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle)
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 WebApp.MagentoWebReference.MagentoService.salesOrderInvoiceList(String sessionId, filters filters) in C:\src\WebApp.2010\WebApp.UI\Web References\MagentoWebReference\Reference.cs:line 3073
at WebApp.Controllers.Magento.MagentoController.GetLatestInvoices() in C:\src\WebApp.2010\WebApp.UI\Controllers\Magento\MagentoController.cs:line 217
--- End of inner exception stack trace ---
I can see that when the response comes back from the Magento API that the XmlSerializer.Deserialize is getting confused and thinks that the XML comes from the Magento 1.5 reference, not the Magento 1.4 reference. The question is why does it do this, and how can it be fixed?
EDIT:
As I suspected the soap envelope of the response from the Magento API is actually the same for both versions:
1.4.1 soap = <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:Magento" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><ns1:loginResponse><loginReturn xsi:type="xsd:string">6325f7753ea72ba70e0a04254d58abe5</loginReturn></ns1:loginResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>
1.5.1 soap = <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:Magento" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><ns1:loginResponse><loginReturn xsi:type="xsd:string">90ebce956623bb7e1637165306de40d0</loginReturn></ns1:loginResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>
Which means that when the response is received, the Xml Deserializer cannot work out which of the web references to use because both of them match the response signature. And it ends up using the Magento1510 reference to deserialize, when it should have been the Magento1411 reference. Is there anything I can do about this? (I have started trying out the answer that suggests to split the references into separate projects)
If the WCF service is versioned in a good way you should be able to talk with the 1.4 version even if you use the 1.5 assemblies. Have you tried this?
If that doesn't work I think you need to seperate the proxy for each version into a new project. This way you can make sure the proxy only knows about the current version and you can avoid the namespace conflicts.