当前位置:编程学习 > C#/ASP.NET >>

【求牛人】c#(winform)调用java的webservice

java的webservice,基于centos+tomcat+axis2发布出来的,
为了安全性使用了rampart模块,通过ws-policy来做策略(不使用的时候可以调用)
在java中需要把rampart模块加入到项目中才可以调用成功,
但是rampart没有c#版本的,所以调用的时候不知道如何去做

【只要把rampart模块干的事,我们自己干了就可以,webservice本来就与语言和平台无关】

webservice的wsdl描述

<?xml version="1.0" encoding="utf-8"?>
<wsdl:definitions xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="http://service.rampart.tutorial" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" targetNamespace="http://service.rampart.tutorial" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
  <wsdl:types>
    <s:schema attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://service.rampart.tutorial">
      <s:element name="add">
        <s:complexType>
          <s:sequence>
            <s:element minOccurs="0" name="a" type="s:int" />
            <s:element minOccurs="0" name="b" type="s:int" />
          </s:sequence>
        </s:complexType>
      </s:element>
      <s:element name="addResponse">
        <s:complexType>
          <s:sequence>
            <s:element minOccurs="0" name="return" type="s:int" />
          </s:sequence>
        </s:complexType>
      </s:element>
      <s:element name="SumMtoN">
        <s:complexType>
          <s:sequence>
            <s:element minOccurs="0" name="x" type="s:int" />
            <s:element minOccurs="0" name="y" type="s:int" />
          </s:sequence>
        </s:complexType>
      </s:element>
      <s:element name="SumMtoNResponse">
        <s:complexType>
          <s:sequence>
            <s:element minOccurs="0" name="return" type="s:int" />
          </s:sequence>
        </s:complexType>
      </s:element>
    </s:schema>
  </wsdl:types>
  <wsdl:message name="addRequest">
    <wsdl:part name="parameters" element="tns:add" />
  </wsdl:message>
  <wsdl:message name="addResponse">
    <wsdl:part name="parameters" element="tns:addResponse" />
  </wsdl:message>
  <wsdl:message name="HelloWorldRequest" />
  <wsdl:message name="HelloWorldResponse" />
  <wsdl:message name="SumMtoNRequest">
    <wsdl:part name="parameters" element="tns:SumMtoN" />
  </wsdl:message>
  <wsdl:message name="SumMtoNResponse">
    <wsdl:part name="parameters" element="tns:SumMtoNResponse" />
  </wsdl:message>
  <wsdl:portType name="WS_rampart3PortType">
    <wsdl:operation name="add">
      <wsdl:input message="tns:addRequest" />
      <wsdl:output message="tns:addResponse" />
    </wsdl:operation>
    <wsdl:operation name="HelloWorld">
      <wsdl:input message="tns:HelloWorldRequest" />
      <wsdl:output message="tns:HelloWorldResponse" />
    </wsdl:operation>
    <wsdl:operation name="SumMtoN">
      <wsdl:input message="tns:SumMtoNRequest" />
      <wsdl:output message="tns:SumMtoNResponse" />
    </wsdl:operation>
  </wsdl:portType>
  <wsdl:binding name="WS_rampart3Soap11Binding" type="tns:WS_rampart3PortType">
    <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document" />
    <wsdl:operation name="add">
      <soap:operation soapAction="urn:add" style="document" />
      <wsdl:input>
        <soap:body use="literal" />
      </wsdl:input>
      <wsdl:output>
        <soap:body use="literal" />
      </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="HelloWorld">
      <soap:operation soapAction="urn:HelloWorld" style="document" />
      <wsdl:input>
        <soap:body use="literal" />
      </wsdl:input>
      <wsdl:output>
        <soap:body use="literal" />
      </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="SumMtoN">
      <soap:operation soapAction="urn:SumMtoN" 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="WS_rampart3Soap12Binding" type="tns:WS_rampart3PortType">
    <soap12:binding transport="http://schemas.xmlsoap.org/soap/http" style="document" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" />
    <wsdl:operation name="add">
      <soap12:operation soapAction="urn:add" style="document" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" />
      <wsdl:input>
        <soap12:body use="literal" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" />
      </wsdl:input>
      <wsdl:output>
        <soap12:body use="literal" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" />
      </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="HelloWorld">
      <soap12:operation soapAction="urn:HelloWorld" style="document" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" />
      <wsdl:input>
        <soap12:body use="literal" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" />
      </wsdl:input>
      <wsdl:output>
        <soap12:body use="literal" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" />
      </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="SumMtoN">
      <soap12:operation soapAction="urn:SumMtoN" style="document" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" />
      <wsdl:input>
        <soap12:body use="literal" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" />
      </wsdl:input>
      <wsdl:output>
        <soap12:body use="literal" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" />
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding>
  <wsdl:binding name="WS_rampart3HttpBinding" type="tns:WS_rampart3PortType">
    <http:binding verb="POST" />
    <wsdl:operation name="add">
      <http:operation location="add" />
      <wsdl:input>
        <mime:content part="parameters" type="application/xml" />
      </wsdl:input>
      <wsdl:output>
        <mime:content part="parameters" type="application/xml" />
      </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="HelloWorld">
      <http:operation location="HelloWorld" />
      <wsdl:input>
        <mime:content part="parameters" type="application/xml" />
      </wsdl:input>
      <wsdl:output>
        <mime:content part="parameters" type="application/xml" />
      </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="SumMtoN">
      <http:operation location="SumMtoN" />
      <wsdl:input>
        <mime:content part="parameters" type="application/xml" />
      </wsdl:input>
      <wsdl:output>
        <mime:content part="parameters" type="application/xml" />
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding>
  <wsdl:service name="WS_rampart3">
    <wsdl:port name="WS_rampart3HttpSoap11Endpoint" binding="tns:WS_rampart3Soap11Binding">
      <soap:address location="http://172.17.5.139/axis2/services/WS_rampart3.WS_rampart3HttpSoap11Endpoint/" />
    </wsdl:port>
    <wsdl:port name="WS_rampart3HttpsSoap11Endpoint" binding="tns:WS_rampart3Soap11Binding">
      <soap:address location="https://172.17.5.139/axis2/services/WS_rampart3.WS_rampart3HttpsSoap11Endpoint/" />
    </wsdl:port>
    <wsdl:port name="WS_rampart3HttpsSoap12Endpoint" binding="tns:WS_rampart3Soap12Binding">
      <soap12:address location="https://172.17.5.139/axis2/services/WS_rampart3.WS_rampart3HttpsSoap12Endpoint/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" />
    </wsdl:port>
    <wsdl:port name="WS_rampart3HttpSoap12Endpoint" binding="tns:WS_rampart3Soap12Binding">
      <soap12:address location="http://172.17.5.139/axis2/services/WS_rampart3.WS_rampart3HttpSoap12Endpoint/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" />
    </wsdl:port>
    <wsdl:port name="WS_rampart3HttpsEndpoint" binding="tns:WS_rampart3HttpBinding">
      <http:address location="https://172.17.5.139/axis2/services/WS_rampart3.WS_rampart3HttpsEndpoint/" />
    </wsdl:port>
    <wsdl:port name="WS_rampart3HttpEndpoint" binding="tns:WS_rampart3HttpBinding">
      <http:address location="http://172.17.5.139/axis2/services/WS_rampart3.WS_rampart3HttpEndpoint/" />
    </wsdl:port>
  </wsdl:service>
</wsdl:definitions>


c#端调用   ramp_tran_443  我生成的web引用

try
{
ramp_tran_443.WS_rampart3 ramp_t_443 = new Webservice.ramp_tran_443.WS_rampart3();
ramp_t_443.Url = "https://172.17.5.139/axis2/services/WS_rampart3?wsdl";
int isum=0;
bool bFlag=false;
ramp_t_443.SumMtoN(Int32.Parse(textBox1.Text),true,Int32.Parse(textBox2.Text),true,out isum,out bFlag);
this.textBox3.Text = isum.ToString();

}
catch(Exception ex)
{
this.textBox4.Text = ex.Message.ToString();
}
finally
{}


报错1.Expected transport is "https" but incoming transport found : "http" 
解决:添加 ramp_t_443.Url = "https://172.17.5.139/axis2/services/WS_rampart3?wsdl"; 
       java的时候,走https,需要把jks硬编码进来,这里没有要,可能还没调到那步 估计

报错2:SOAP header missing
求助:
补充:.NET技术 ,  C#
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,