因此,我在NetBeans 6.5生成的Java ME客戶端的Web服務代碼到c#(vs2005)Web服務上發生了一些編譯錯誤。我已經對我的示例進行了大量修改,並且仍然顯示了問題,並且無法返回一組東西幾乎是一種破壞行爲。從.net Web服務將數組返回到Java ME Web服務會導致存根編譯錯誤?
C#web服務(SimpleWebService.asmx)
<%@ WebService Language="C#" Class="SimpleWebService" %>
using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
[WebService(Namespace = "http://sphereinabox.com/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class SimpleWebService : System.Web.Services.WebService {
[WebMethod]
public CustomType[] GetSomething() {
return new CustomType[] {new CustomType("hi"), new CustomType("bye")};
}
public class CustomType {
public string Name;
public CustomType(string _name) {
Name = _name;
}
public CustomType() {
}
}
}
WSDL(由VS2005自動生成):
<?xml version="1.0" encoding="utf-8"?>
<wsdl:definitions xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:tns="http://sphereinabox.com/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" targetNamespace="http://sphereinabox.com/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
<wsdl:types>
<s:schema elementFormDefault="qualified" targetNamespace="http://sphereinabox.com/">
<s:element name="GetSomething">
<s:complexType />
</s:element>
<s:element name="GetSomethingResponse">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="GetSomethingResult" type="tns:ArrayOfCustomType" />
</s:sequence>
</s:complexType>
</s:element>
<s:complexType name="ArrayOfCustomType">
<s:sequence>
<s:element minOccurs="0" maxOccurs="unbounded" name="CustomType" nillable="true" type="tns:CustomType" />
</s:sequence>
</s:complexType>
<s:complexType name="CustomType">
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="Name" type="s:string" />
</s:sequence>
</s:complexType>
</s:schema>
</wsdl:types>
<wsdl:message name="GetSomethingSoapIn">
<wsdl:part name="parameters" element="tns:GetSomething" />
</wsdl:message>
<wsdl:message name="GetSomethingSoapOut">
<wsdl:part name="parameters" element="tns:GetSomethingResponse" />
</wsdl:message>
<wsdl:portType name="SimpleWebServiceSoap">
<wsdl:operation name="GetSomething">
<wsdl:input message="tns:GetSomethingSoapIn" />
<wsdl:output message="tns:GetSomethingSoapOut" />
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="SimpleWebServiceSoap" type="tns:SimpleWebServiceSoap">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" />
<wsdl:operation name="GetSomething">
<soap:operation soapAction="http://sphereinabox.com/GetSomething" 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="SimpleWebServiceSoap12" type="tns:SimpleWebServiceSoap">
<soap12:binding transport="http://schemas.xmlsoap.org/soap/http" />
<wsdl:operation name="GetSomething">
<soap12:operation soapAction="http://sphereinabox.com/GetSomething" 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="SimpleWebService">
<wsdl:port name="SimpleWebServiceSoap" binding="tns:SimpleWebServiceSoap">
<soap:address location="http://localhost/SimpleWebService/SimpleWebService.asmx" />
</wsdl:port>
<wsdl:port name="SimpleWebServiceSoap12" binding="tns:SimpleWebServiceSoap12">
<soap12:address location="http://localhost/SimpleWebService/SimpleWebService.asmx" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
生成(netbeans的)代碼編譯失敗,這創建經歷的「添加 - >新的JavaME到Web服務客戶端」嚮導。 (SimpleWebService_Stub.java)
public ArrayOfCustomType GetSomething() throws java.rmi.RemoteException {
Object inputObject[] = new Object[] {
};
Operation op = Operation.newInstance(_qname_operation_GetSomething, _type_GetSomething, _type_GetSomethingResponse);
_prepOperation(op);
op.setProperty(Operation.SOAPACTION_URI_PROPERTY, "http://sphereinabox.com/GetSomething");
Object resultObj;
try {
resultObj = op.invoke(inputObject);
} catch(JAXRPCException e) {
Throwable cause = e.getLinkedCause();
if(cause instanceof java.rmi.RemoteException) {
throw (java.rmi.RemoteException) cause;
}
throw e;
}
//////// Error on next line, symbol ArrayOfCustomType_fromObject not defined
return ArrayOfCustomType_fromObject((Object[])((Object[]) resultObj)[0]);
}
原來用(在我的生產問題「CustomType」有一個以上的場)這個人爲的例子我也從產生相同的這個有趣的代碼得到錯誤(SimpleWebService_Stub.java )生成的代碼。錯誤是沒有定義字符串(它是Java中的String,除此之外我認爲這應該是談論CustomType)。
private static string string_fromObject(Object obj[]) {
if(obj == null) return null;
string result = new string();
return result;
}