c# – Zend Framework 2 SOAP与.NET不兼容
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了c# – Zend Framework 2 SOAP与.NET不兼容,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1856字,纯文字阅读大概需要3分钟。
内容图文
我正在尝试在我的ZF2应用程序中创建一个SOAP服务器,我可以使用向导将Visual Studio导入到C#应用程序中.我已经创建了服务并使用soapUI对其进行了测试.我在soapUI中运行了WS-I一致性测试,我的服务通过了它.但是,当我尝试使用Visual C#Express 2008将服务添加到C#应用程序时,它表示HTML文档没有Web服务发现信息.
这是我在ZF2控制器中使用的代码:
public function exampleAction() {
if (isset($_GET['wsdl'])) {
$soapAutoDiscover = new AutoDiscover();
$soapAutoDiscover->setBindingStyle(array('style' => 'document'));
$soapAutoDiscover->setOperationBodyStyle(array('use' => 'literal'));
$soapAutoDiscover->setClass('SoapClass');
$soapAutoDiscover->setUri($serverUrl);
echo $soapAutoDiscover->generate()->toXml();
} else {
$soap = new Server($serverUrl . '?wsdl');
$soap->setClass('SoapClass');
$soap->handle();
}
}
这是SoapClass类:
class SoapClass{
/**
* returns the sum of two parameters
* @param int $a
* @param int $b
* @return int
*/
public function sum ($a, $b){
return $a + $b;
}
/**
* twice function doc
* @param int $a
* @return int
*/
public function twice($a){
return $a * 2;
}
}
有任何想法吗?
解决方法:
在阅读并重读了我在此发现的一些帖子和文档之后,终于遇到了de解决方案:
SoapClass很好,但是在生成wsdl和服务器的那一刻我不得不做一些改变:
public function exampleAction() {
if (isset($_GET['wsdl'])) {
//this is new:
$soapAutoDiscover = new AutoDiscover(new \Zend\Soap\Wsdl\ComplexTypeStrategy\ArrayOfTypeSequence());
$soapAutoDiscover->setBindingStyle(array('style' => 'document'));
$soapAutoDiscover->setOperationBodyStyle(array('use' => 'literal'));
$soapAutoDiscover->setClass('SoapClass');
$soapAutoDiscover->setUri($serverUrl);
//so this is:
header("Content-Type: text/xml");
echo $soapAutoDiscover->generate()->toXml();
} else {
$soap = new Server($serverUrl . '?wsdl');
//drop this:
//$soap->setClass('SoapClass');
//and instead, add this:
$soap->setObject(new DocumentLiteralWrapper(new SoapClass()));
$soap->handle();
}
}
内容总结
以上是互联网集市为您收集整理的c# – Zend Framework 2 SOAP与.NET不兼容全部内容,希望文章能够帮你解决c# – Zend Framework 2 SOAP与.NET不兼容所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。