मैं इसके साथ भी संघर्ष कर रहा हूं, विशेष रूप से कोड प्राप्त करना जो नेट क्लाइंट के साथ अच्छी तरह से काम करता है। मुझे ऐसे उदाहरण मिल गए हैं जो PHP क्लाइंट के साथ अच्छी तरह से काम करते हैं, लेकिन जब मैं .NET क्लाइंट से सेवा को कॉल करने का प्रयास करता हूं तो अक्सर ये उदाहरण विफल हो जाते हैं। मैं अभी भी इस के साथ संघर्ष कर रहा हूँ इसलिए एक सरल पीएचपी SoapServer उदाहरण है कि एक स्ट्रिंग मान देता है के साथ मदद के लिए पूछ मेरा यह प्रश्न:,
String values returned by PHP SoapServer not received by .Net client
लेकिन हालांकि मैं इस बुनियादी उदाहरण काम नहीं कर प्राप्त कर सकते हैं, मैं एक उदाहरण प्राप्त करने में कामयाब रहा है जो कस्टम ऑब्जेक्ट की एक सरणी देता है, इसलिए मैं इस उदाहरण को उम्मीद में साझा करूंगा कि यह दूसरों के लिए सहायक होगा। यह उदाहरण एक ऑपरेशन getUsers परिभाषित करता है जो स्ट्रिंग पैरामीटर संदेश लेता है, बस संदेश पास करने का प्रदर्शन करने के लिए। यह ऑपरेशन उपयोगकर्ता ऑब्जेक्ट्स की एक सरणी देता है। उपयोगकर्ता ऑब्जेक्ट में फ़ील्ड संदेश है जहां मैं परीक्षण उद्देश्यों के लिए सेवा में प्राप्त मूल्य को वापस पास करता हूं। मैं पूरा उदाहरण पोस्ट करूंगा; wsdl दस्तावेज़, PHP सर्वर कोड और सी # क्लाइंट कोड।
WSDL दस्तावेज़
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
xmlns:tns="http://test-uri/soap/export/"
xmlns:s="http://www.w3.org/2001/XMLSchema"
xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"
xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
targetNamespace="http://test-uri/soap/export/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
<wsdl:types>
<s:schema targetNamespace="http://test-uri/soap/export/" elementFormDefault="qualified">
<s:import namespace="http://microsoft.com/wsdl/types/"/>
<s:element name="getUsers">
<s:complexType>
<s:sequence>
<s:element minOccurs="1" maxOccurs="1" name="message" type="s:string"/>
</s:sequence>
</s:complexType>
</s:element>
<s:element name="getUsersResponse">
<s:complexType>
<s:sequence>
<s:element name="getUsersArray" type="tns:getUsersArray"/>
</s:sequence>
</s:complexType>
</s:element>
<s:complexType name="getUsersArray">
<s:sequence>
<s:element minOccurs="0" maxOccurs="unbounded" name="User" nillable="true" type="tns:User" />
</s:sequence>
</s:complexType>
<s:complexType name="User">
<s:sequence>
<s:element minOccurs="1" maxOccurs="1" name="id" type="s:string"/>
<s:element minOccurs="1" maxOccurs="1" name="firstname" type="s:string"/>
<s:element minOccurs="1" maxOccurs="1" name="surname" type="s:string"/>
<s:element minOccurs="1" maxOccurs="1" name="message" type="s:string"/>
</s:sequence>
</s:complexType>
</s:schema>
</wsdl:types>
<wsdl:message name="getUsersSoapIn">
<wsdl:part name="parameters" element="tns:getUsers"/>
</wsdl:message>
<wsdl:message name="getUsersSoapOut">
<wsdl:part name="parameters" element="tns:getUsersResponse"/>
</wsdl:message>
<wsdl:portType name="TestSoap">
<wsdl:operation name="getUsers">
<wsdl:documentation xmlns:wsdl='http://schemas.xmlsoap.org/wsdl/'>
Function ("getUsers")
</wsdl:documentation>
<wsdl:input message="tns:getUsersSoapIn"/>
<wsdl:output message="tns:getUsersSoapOut"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:portType name="TestSoap12">
<wsdl:operation name="getUsers">
<wsdl:documentation xmlns:wsdl='http://schemas.xmlsoap.org/wsdl/'>
Function ("getUsers")
</wsdl:documentation>
<wsdl:input message="tns:getUsersSoapIn"/>
<wsdl:output message="tns:getUsersSoapOut"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="TestSoap" type="tns:TestSoap">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="getUsers">
<soap:operation soapAction="http://test-uri/soap/export/getUsers" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:binding name="TestSoap12" type="tns:TestSoap12">
<soap12:binding transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="getUsers">
<soap12:operation soapAction="http://test-uri/soap/export/getUsers" style="document"/>
<wsdl:input>
<soap12:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap12:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="TestService">
<wsdl:port name="TestPort" binding="tns:TestSoap">
<soap:address location="http://url/to/test_server.php"/>
</wsdl:port>
<wsdl:port name="TestSoap12" binding="tns:TestSoap12">
<soap12:address location="http://url/to/test_server.php"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
पीएचपी सर्वर कोड
<?php
function getUsers($args) {
$args = (array)$args;
return array("getUsersArray" => array(
array("id"=>"1",
"firstname"=>"Barney",
"surname"=>"Rubble",
"message"=>$args["message"]),
array("id"=>"2",
"firstname"=>"Fred",
"surname"=>"Flintstone",
"message"=>$args["message"])
)
);
}
ini_set("soap.wsdl_cache_enabled", "0"); // disabling WSDL cache
$server = new SoapServer("test.wsdl");
$server->addFunction("getUsers");
try {
$server->handle();
}
catch (Exception $e) {
$server->fault('Sender', $e->getMessage());
}
?>
सी # क्लाइंट कोड
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
WebReference.TestService srv = new WebReference.TestService();
WebReference.User[] users = srv.getUsers("says hello");
foreach (WebReference.User user in users)
{
MessageBox.Show(user.firstname+" "+user.message);
}
}
}
}
यह है कि। मुझे उम्मीद है कि यह उदाहरण दूसरों के लिए उपयोगी है और उन्हें उन घंटों को बचाता है जिनके लिए मुझे लागत है !!
2 अंक ध्यान दें कि आपको समय बचा सकता है; सबसे पहले, इस बग को समझने के लिए समय लें: https://bugs.php.net/bug.php?id=49169; दूसरा, स्कीमा सत्यापन पर भरोसा न करें, मेरे अनुभव में सभी एक्सएमएल स्कीमा नियमों की जांच नहीं की जाती है। – Robin