[英]Problems calling Magento SOAP V2 Service in C#
I'm hosting a magento webshop on my local machine using IIS 7.5 and PHP 5.6 (testing). 我正在使用IIS 7.5和PHP 5.6(测试)在本地计算机上托管一个magento网上商店。 The shop is working just fine, but now I want to create a separate application using visual studio 2013. These are the steps that I've taken:
商店工作得很好,但现在我想使用Visual Studio 2013创建一个单独的应用程序。这些是我已经采取的步骤:
Here is my piece of code: 这是我的代码:
class Program
{
static void Main(string[] args)
{
MainAsync(args).Wait();
}
static async Task MainAsync(string[] args)
{
using (var proxy = new Mage_Api_Model_Server_Wsi_HandlerPortTypeClient())
{
try
{
var loginResponse = await proxy.loginAsync("soap-admin", "xxxxxxxxx"); // api key
var sessionId = loginResponse.result;
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
Console.ReadLine();
}
}
}
And this is the error I'm getting: 这是我得到的错误:
The content type text/xml; charset=utf-8,text/xml; charset=utf-8 of the response message does not match the content type of the binding (text/xml; charset=utf-8). If using a custom encoder, be sure that the IsContentTypeSupported method is implemented properly. The first 297 bytes of the response were: '<?xml version="1.0" encoding="utf-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:Magento">
<SOAP-ENV:Body>
<ns1:loginResponseParam>
<result>13fa067676759c3ce8ddd61c386b6d5c</result>
</ns1:loginResponseParam>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
'.
So as you can see, I'm getting my sessionId but keep getting this error. 如您所见,我正在获取我的sessionId,但始终收到此错误。 I've also used fiddler to investigate and getting a correct response: HTTP 200 OK.
我还使用提琴手进行调查并获得正确的响应:HTTP 200 OK。 Does someone knows what the problem could be?
有人知道可能是什么问题吗? Is it IIS related?
与IIS相关吗? localhost related?
本地主机相关吗?
(When I add the url as web reference it works just fine - old webservice method). (当我将URL添加为Web引用时,它可以正常工作-旧的webservice方法)。
Related topics I've read and tried (without success): 我已阅读并尝试过的相关主题(没有成功):
If got this answer from Rian at Magento Stack Exchange . 如果从Magento Stack Exchange的 Rian那里得到了这个答案。 All credits go to Rian
所有学分归Rian所有
The solution: 解决方案:
The problem you're experiencing is that .NET/C# is having trouble parsing the content type Magento is sending along with it's response. 您遇到的问题是.NET / C#无法解析Magento随其响应发送的内容类型。 SOAP is notoriously finicky about receiving just the right stuff in just the right format.
众所周知,SOAP以正确的格式接收正确的内容是挑剔的。 Couple that with PHP's rather poor implementation of the protocol and you're in for a lot of fun.
将其与PHP协议的较差实现相结合,您将获得很多乐趣。
I'm looking at a Magento 1.9 for the following information: 我正在寻找Magento 1.9,以获取以下信息:
After some digging I found that the header for the SOAP calls are set in app/code/core/Mage/Api/Model/Server/V2/Adapter/Soap.php
on line 52. 经过一番挖掘后,我发现在第52行的
app/code/core/Mage/Api/Model/Server/V2/Adapter/Soap.php
中设置了SOAP调用的标头。
51. ->clearHeaders()
52. ->setHeader('Content-Type','text/xml; charset='.$apiConfigCharset)
53. ->setBod...
Note that that Content-Type header matches your text/xml; charset=utf-8
请注意,Content-Type标头与您的
text/xml; charset=utf-8
相匹配text/xml; charset=utf-8
text/xml; charset=utf-8
desired charset. text/xml; charset=utf-8
所需的字符集。 Adjusting line 52 to: 将第52行调整为:
52. ->setHeader('Content-Type','text/xml; charset='.$apiConfigCharset, true)
tells Magento to force overwriting that header if it's already set. 告诉Magento强制覆盖已设置的标头。
Make sure to make a copy of the file with it's full path to the app/code/local/Mage/...
to avoid overwriting core files. 确保使用该文件的完整路径复制一份文件到
app/code/local/Mage/...
以避免覆盖核心文件。 You'll thank me when you want to upgrade Magento at some point. 当您想升级Magento时,会感谢我。
Also, make sure to look carefully, there's two setHeader() calls in that file. 另外,请确保仔细查看,该文件中有两个setHeader()调用。
And finally, there's also a WS-I compliant SOAP adapter available, the same fix applies to that file. 最后,还有一个兼容WS-I的SOAP适配器,相同的修复程序适用于该文件。 You can find it in
app/code/core/Mage/Api/Model/Server/Wsi/Adapter/Soap.php
. 您可以在
app/code/core/Mage/Api/Model/Server/Wsi/Adapter/Soap.php
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.