您的位置:程序门 -> .net技术 -> web services



如何开发 .net客户调用java 的 web service


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


如何开发 .net客户调用java 的 web service
发表于:2008-01-13 06:36:49 楼主
我用java   cxf   写的web   service,已经用java客户调试通过了.但是.net客户还不行.我对.net一点也不懂.
弄了2天了,还是不知道为何不行.   以下是我的步骤:
1)creat   a   web   site;
2)添加web引用,   在url   中输入

问题开始出现了,我java定义的   web   service   接受2个参数,并声明抛出一个异常.
  string   sayhi(string   text,   profile   info)   throws   businesslogicexception;

现在它不能够正确找到方法.它找到的方法:
  sayhi(textas   string)   as   string
但是丢了一个profile   info   参数和异常!

3)如果我在   .cs   文件调用就出错,因为根本没法编译   localhost.helloworldimpservice
另外,如果我添加   service   引用,servicereference   可以找到profile,   businesslogicexception.

以下是我的wsdl文件.哪位大虾指点一下啊.

<?xml   version="1.0"   encoding="utf-8"?> <wsdl:definitions   xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"   xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"   xmlns:tns="http://spring.demo/"   xmlns:xsd="http://www.w3.org/2001/xmlschema"   name="helloworldservice"   targetnamespace="http://spring.demo/">
    <wsdl:types>
<xs:schema   xmlns:xs="http://www.w3.org/2001/xmlschema"   attributeformdefault="unqualified"   elementformdefault="unqualified"   targetnamespace="http://spring.demo/"   xmlns:tns="http://spring.demo/">
<xs:element   name="businesslogicfaultdetail"   nillable="true"   type="tns:businesslogicfaultdetail"/>
<xs:element   name="sayhi"   nillable="true"   type="tns:sayhi"/>
<xs:element   name="sayhiresponse"   nillable="true"   type="tns:sayhiresponse"/>
<xs:complextype   name="sayhi">
<xs:sequence>
<xs:element   minoccurs="0"   name="text"   type="xs:string"/>
<xs:element   minoccurs="0"   name="info"   type="tns:profileinfo"/>
</xs:sequence>
</xs:complextype>
<xs:complextype   name="profileinfo">
<xs:sequence>
<xs:element   minoccurs="0"   name="addressline1"   type="xs:string"/>
<xs:element   minoccurs="0"   name="addressline2"   type="xs:string"/>
<xs:element   minoccurs="0"   name="city"   type="xs:string"/>
<xs:element   minoccurs="0"   name="companyname"   type="xs:string"/>
<xs:element   minoccurs="0"   name="email"   type="xs:string"/>
<xs:element   minoccurs="0"   name="fax"   type="xs:string"/>
<xs:element   minoccurs="0"   name="firstname"   type="xs:string"/>
<xs:element   minoccurs="0"   name="lastname"   type="xs:string"/>
<xs:element   minoccurs="0"   name="middlename"   type="xs:string"/>
<xs:element   minoccurs="0"   name="mobile"   type="xs:string"/>
<xs:element   minoccurs="0"   name="phone"   type="xs:string"/>
<xs:element   minoccurs="0"   name="state"   type="xs:string"/>
<xs:element   minoccurs="0"   name="status"   type="xs:string"/>
<xs:element   minoccurs="0"   name="zip"   type="xs:string"/>
</xs:sequence>
</xs:complextype>
<xs:complextype   name="sayhiresponse">
<xs:sequence>
<xs:element   minoccurs="0"   name="return"   type="xs:string"/>
</xs:sequence>
</xs:complextype>
<xs:complextype   name="businesslogicfaultdetail"/>
</xs:schema>
    </wsdl:types>
    <wsdl:message   name="businesslogicexception">
        <wsdl:part   element="tns:businesslogicfaultdetail"   name="businesslogicexception">
        </wsdl:part>
    </wsdl:message>
    <wsdl:message   name="sayhiresponse">
        <wsdl:part   element="tns:sayhiresponse"   name="parameters">
        </wsdl:part>
    </wsdl:message>
    <wsdl:message   name="sayhi">
        <wsdl:part   element="tns:sayhi"   name="parameters">
        </wsdl:part>
    </wsdl:message>
    <wsdl:porttype   name="helloworld">
        <wsdl:operation   name="sayhi">
            <wsdl:input   message="tns:sayhi"   name="sayhi">
        </wsdl:input>
            <wsdl:output   message="tns:sayhiresponse"   name="sayhiresponse">
        </wsdl:output>
            <wsdl:fault   message="tns:businesslogicexception"   name="businesslogicexception">
        </wsdl:fault>
        </wsdl:operation>
    </wsdl:porttype>
    <wsdl:binding   name="helloworldservicesoapbinding"   type="tns:helloworld">
        <soap:binding   style="document"   transport="http://schemas.xmlsoap.org/soap/http"/>
        <wsdl:operation   name="sayhi">
            <soap:operation   soapaction=""   style="document"/>
            <wsdl:input   name="sayhi">
                <soap:body   use="literal"/>
            </wsdl:input>
            <wsdl:output   name="sayhiresponse">
                <soap:body   use="literal"/>
            </wsdl:output>
            <wsdl:fault   name="businesslogicexception">
                <soap:fault   name="businesslogicexception"   use="literal"/>
            </wsdl:fault>
        </wsdl:operation>
    </wsdl:binding>
    <wsdl:service   name="helloworldservice">
        <wsdl:port   binding="tns:helloworldservicesoapbinding"   name="helloworldport">
            <soap:address   location="http://localhost:9090/spring_http/ws/serverendpoint"/>
        </wsdl:port>
    </wsdl:service>
</wsdl:definitions>
发表于:2008-01-13 06:53:131楼 得分:0
大家都说:   在vs中添加web引用,然后在url   中直接输入webservice地址,添加引用就可以了  
为什么引用不能够正确找到方法?
另外我也试用了wsdl.exe,以下是生成的   cs   文件.不知道怎么没有异常的代码.不知道正确否.
我头都大了,大家帮帮我.

//不准我贴cs文件,说太长了:(
发表于:2008-01-13 20:44:392楼 得分:0
.net引用ws的时候不是由命名空间么,

会不会你没有用命名空间呢???

命名空间让你就像使用本地组件一样用ws

发表于:2008-01-13 23:54:363楼 得分:0
在哪里定义命名空间?   我的   wsdl文件   里面是否已经正确定义了命名空间?
我试了试,
 
如果我java定义的是:   string   sayhi(string   text);
web引用能够正确找到方法.它找到的方法:
    sayhi(textas   string)   as   string

但是如果我java定义是:   string   sayhi(string   text,   profile   info)   throws   businesslogicexception;
web引用找到的方法还是:
    sayhi(textas   string)   as   string
就是找不到   profile   info   参数和异常!  



快速检索

最新资讯
热门点击