Silverlight 和 NuSoap
编辑:经过一些研究,我找到了问题的答案(至少它适用于我的特定情况)。我现在使用以下调用,而不是下面提到的寄存器调用:
$soap->register(
'MyFunction',
array('inputData' => 'xsd:string'),
array('outputData' => 'xsd:string'),
$namespace,
$namespace . "#MyFunction",
"rpc",
"literal",
"My description.");
我猜“rpc”和“literal”参数是成功的关键。希望这能帮助其他面临同样问题的用户。
我在一个新项目中遇到问题,其中 silverlight 应用程序要从 NuSoap 服务请求数据。由于这种集成对我来说相当新,不幸的是,在互联网上找不到太多有关该主题的资源(至少没有解决我的问题),我希望有人能指出我正确的方向。
NuSoap 部分的实现如下:
<?php
require_once('../soap/nusoap/nusoap.php');
$namespace = "http://127.0.0.1/adminSoap";
$soap = new Soap_Server();
$soap->configureWSDL('MyService', $namespace);
$soap->wsdl->schemaTargetNameSpace = $namespace;
$soap->soap_defencoding = 'utf-8';
$soap->register(
'MyFunction',
array('inputData' => 'xsd:string'),
array('outputData' => 'xsd:string'),
$namespace
);
$soap->service(isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '');
function MyFunction($inputData)
{
return "ok";
}
?>
然后,我添加对此服务的 Web 引用,并获得一个对话框,我可以在其中选择该服务、其 ServicePortType 以及“MyFunction”。
但是,如果我生成引用,我会假设找到自动生成的 MyFunction 异步消息(即 MyFunctionAsync 和 MyFunctionCompleted.event)。这些都不存在。
我可能做错了什么。这是设置客户端的代码:
ServiceReference4.MyServicePortTypeClient client = new SilverlightTest1.ServiceReference4.MyServicePortTypeClient();
有什么想法为什么异步方法不可用吗?
这是生成的 WSDL,如果有任何帮助的话,顺便说一句(由于从 IE 复制/粘贴而产生连字符):
<definitions targetNamespace="http://127.0.0.1/adminSoap">
−
<types>
−
<xsd:schema targetNamespace="http://127.0.0.1/adminSoap">
<xsd:import namespace="http://schemas.xmlsoap.org/soap/encoding/"/>
<xsd:import namespace="http://schemas.xmlsoap.org/wsdl/"/>
</xsd:schema>
</types>
−
<message name="MyFunctionRequest">
<part name="affiliate" type="xsd:string"/>
</message>
−
<message name="MyFunctionResponse">
<part name="result" type="xsd:string"/>
</message>
−
<portType name="MyServicePortType">
−
<operation name="MyFunction">
<input message="tns:MyFunctionRequest"/>
<output message="tns:MyFunctionResponse"/>
</operation>
</portType>
−
<binding name="MyServiceBinding" type="tns:MyServicePortType">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
−
<operation name="MyFunction">
<soap:operation soapAction="http://127.0.0.1/magento/adminSoap/SoapStatsService.php/MyFunction" style="rpc"/>
−
<input>
<soap:body use="encoded" namespace="http://127.0.0.1/adminSoap" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
−
<output>
<soap:body use="encoded" namespace="http://127.0.0.1/adminSoap" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
</binding>
−
<service name="MyService">
−
<port name="MyServicePort" binding="tns:MyServiceBinding">
<soap:address location="http://127.0.0.1/magento/adminSoap/SoapStatsService.php"/>
</port>
</service>
</definitions>
EDIT: After some research, I found the answer to the problem (at least it works for my particular situation). Instead of the register call noted down below, I am now using the following call:
$soap->register(
'MyFunction',
array('inputData' => 'xsd:string'),
array('outputData' => 'xsd:string'),
$namespace,
$namespace . "#MyFunction",
"rpc",
"literal",
"My description.");
I guess the "rpc" and "literal" arguments are the key to the success. Hopefully this will help some other users facing the same problem.
I have a problem with a new project, where a silverlight application is to request data from a NuSoap-service. As this integration is rather new to me and unfortunately not many resources concerning this topic can be found on the internet (none addressing my problem at least), I hope that someone can point me into the correct direction.
The NuSoap-part is implemented like this:
<?php
require_once('../soap/nusoap/nusoap.php');
$namespace = "http://127.0.0.1/adminSoap";
$soap = new Soap_Server();
$soap->configureWSDL('MyService', $namespace);
$soap->wsdl->schemaTargetNameSpace = $namespace;
$soap->soap_defencoding = 'utf-8';
$soap->register(
'MyFunction',
array('inputData' => 'xsd:string'),
array('outputData' => 'xsd:string'),
$namespace
);
$soap->service(isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '');
function MyFunction($inputData)
{
return "ok";
}
?>
I then add a web reference to this service and get the dialog where I can select the service, its ServicePortType as well as "MyFunction".
If I generate the reference however, I would assume to find automatically generated asynchronous messages for MyFunction (i.e. MyFunctionAsync and the MyFunctionCompleted.event). These do not exist.
What could I be doing wrong. Here's the code that sets up the client:
ServiceReference4.MyServicePortTypeClient client = new SilverlightTest1.ServiceReference4.MyServicePortTypeClient();
Any ideas why the asynchronous method is not available?
Here's the generated WSDL, if that's of any help, btw (hyphens due to copy/paste from IE):
<definitions targetNamespace="http://127.0.0.1/adminSoap">
−
<types>
−
<xsd:schema targetNamespace="http://127.0.0.1/adminSoap">
<xsd:import namespace="http://schemas.xmlsoap.org/soap/encoding/"/>
<xsd:import namespace="http://schemas.xmlsoap.org/wsdl/"/>
</xsd:schema>
</types>
−
<message name="MyFunctionRequest">
<part name="affiliate" type="xsd:string"/>
</message>
−
<message name="MyFunctionResponse">
<part name="result" type="xsd:string"/>
</message>
−
<portType name="MyServicePortType">
−
<operation name="MyFunction">
<input message="tns:MyFunctionRequest"/>
<output message="tns:MyFunctionResponse"/>
</operation>
</portType>
−
<binding name="MyServiceBinding" type="tns:MyServicePortType">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
−
<operation name="MyFunction">
<soap:operation soapAction="http://127.0.0.1/magento/adminSoap/SoapStatsService.php/MyFunction" style="rpc"/>
−
<input>
<soap:body use="encoded" namespace="http://127.0.0.1/adminSoap" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
−
<output>
<soap:body use="encoded" namespace="http://127.0.0.1/adminSoap" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
</binding>
−
<service name="MyService">
−
<port name="MyServicePort" binding="tns:MyServiceBinding">
<soap:address location="http://127.0.0.1/magento/adminSoap/SoapStatsService.php"/>
</port>
</service>
</definitions>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我正在研究类似的问题。我使用 Zend_Soap(它只包装了 PHP SOAP 扩展),并使用 Silverlight 服务参考来连接它。看来 Silverlight 服务实现无法使我们使用肥皂编码操作。如果您查看每个 WSDL 下都有一个 和 。这些标签中的属性让我们都感到沮丧。 use="encoded" 和encodingStyle="blah, blah" 属性。
我现在知道 Zend_Soap 只会进行使用肥皂编码的绑定。我还不确定 nuSoap 的情况。
如果您可以更改 PHP 后端,您可能会考虑 Midnight Coders WebORB for PHP 和 Silverlight。它包括一个服务器和客户端协同工作的解决方案。在某些情况下它是免费的。由于许可问题,我无法使用它。
I working on a similar problem. I was using Zend_Soap (which just wraps the PHP SOAP extension), and using a Silverlight Service Reference to connect to it. It seems that the Silverlight Service implementation cannot make us of soap-encoded operations. If you look at the WSDL under each has an and . In those tags are the the attributes that damn us both to frustration. The use="encoded" and encodingStyle="blah, blah" attributes.
I now know that Zend_Soap will only make bindings that use soap-encoding. I'm not sure yet about nuSoap.
If you can change the PHP backend, you might look into Midnight Coders WebORB for PHP and Silverlight. It includes a solution for both the server and the client that work together. It is available for free for certain circumstances. Due to licensing issues, I don't I'll be able to us it.