2013-05-13 2 views
3

pywssuds으로 간단한 웹 서비스 서버를 구현했습니다.Python WS 서버 및 Java WS 클라이언트

<?xml version="1.0" encoding="UTF-8"?> 
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> 
    <soap:Body> 
    <soap:Fault> 
     <faultcode>soap:Client</faultcode> 
     <faultstring>None</faultstring> 
     <detail> 
     <name>XMLSyntaxError</name> 
     <prefix>lxml.etree</prefix> 
     <exceptionName>comtypes.example.Error</exceptionName> 
     <params> 
      <item xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/> 
     </params> 
     <message>None</message> 
     <type>Client</type> 
     </detail> 
    </soap:Fault> 
    </soap:Body> 
</soap:Envelope> 

그리고 http://localhost:8000/soa/wsdl :

<?xml version="1.0" encoding="UTF-8"?> 
<wsdl:definitions xmlns:types="http://example.comtypes/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://example.com" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://example.com" name="Test"> 
    <wsdl:types> 
    <xsd:schema elementFormDefault="qualified" targetNamespace="http://example.comtypes/" attributeFormDefault="qualified" xmlns="http://example.comtypes/"> 
     <xsd:element name="add_simple"> 
     <xsd:complexType> 
      <xsd:sequence> 
      <xsd:element type="xsd:string" name="a" nillable="true"/> 
      <xsd:element type="xsd:string" name="b" nillable="true"/> 
      </xsd:sequence> 
     </xsd:complexType> 
     </xsd:element> 
     <xsd:element name="add_simple_result"> 
     <xsd:complexType> 
      <xsd:sequence> 
      <xsd:element type="xsd:string" name="result" nillable="true"/> 
      </xsd:sequence> 
     </xsd:complexType> 
     </xsd:element> 
     <xsd:element name="Error"> 
     <xsd:complexType> 
      <xsd:sequence/> 
     </xsd:complexType> 
     </xsd:element> 
    </xsd:schema> 
    <xsd:schema targetNamespace="http://example.com"> 
     <xsd:import namespace="http://example.comtypes/"/> 
    </xsd:schema> 
    </wsdl:types> 
    <wsdl:message name="error"> 
    <wsdl:part name="fault" element="types:Error"/> 
    </wsdl:message> 
    <wsdl:message name="add_simple"> 
    <wsdl:part name="parameters" element="types:add_simple"/> 
    </wsdl:message> 
    <wsdl:message name="add_simple_result"> 
    <wsdl:part name="parameters" element="types:add_simple_result"/> 
    </wsdl:message> 
    <wsdl:portType name="TestPortType"> 
    <wsdl:operation name="add_simple"> 
     <wsdl:input message="tns:add_simple"/> 
     <wsdl:output message="tns:add_simple_result"/> 
     <wsdl:fault message="tns:error" name="error"/> 
    </wsdl:operation> 
    </wsdl:portType> 
    <wsdl:binding type="tns:TestPortType" name="TestBinding"> 
    <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/> 
    <wsdl:operation name="add_simple"> 
     <soap:operation soapAction="http://example.comadd_simple"/> 
     <wsdl:input> 
     <soap:body use="literal"/> 
     </wsdl:input> 
     <wsdl:output> 
     <soap:body use="literal"/> 
     </wsdl:output> 
     <wsdl:fault name="error"> 
     <soap:fault use="literal" name="error"/> 
     </wsdl:fault> 
    </wsdl:operation> 
    </wsdl:binding> 
    <wsdl:service name="TestService"> 
    <wsdl:port binding="tns:TestBinding" name="TestPort"> 
     <soap:address location="http://localhost:8000/soa/"/> 
    </wsdl:port> 
    </wsdl:service> 
</wsdl:definitions> 
>>> import suds 
>>> client = suds.client.Client('http://localhost:8000/soa/wsdl', cache=None) 
>>> client.service.add_simple('hello ', 'world') 
hello world 

이를 생성합니다 http://localhost:8000/soa 액세스 :

from pyws.server import SoapServer 
from pyws.functions.register import register 

server = SoapServer(
     service_name = 'Test', 
     tns = 'http://example.com', 
     location = 'http://localhost:8000/soa/', 
) 

@register() 
def add_simple(a, b): 
    return a + b 

내가 파이썬 쉘에 액세스 할 수있는 방법입니다Java (이 단순함을 위해) 콘솔 응용 프로그램에이 서비스 양식을 액세스하려면 어떻게해야합니까? 자바 클라이언트에서 일반적으로이 beacause를 묻습니다. 사용하려고하는 클래스의 인스턴스를 만들 것이고,이 경우에는 적용 할 수 없습니다.
이클립스 웹 서비스 브라우저를 사용하여이 웹 서비스를 테스트했는데 작동했음을 언급해야합니다. 자바 프로그램에서이를 통합하는 방법을 모르겠습니다.

답변

0

주 방법으로 하나 이상의 클래스를 만들어야합니다. 그래서 컴파일 후, 당신은 같은 명령 사용할 수 있습니다

자바 클래스 이름의 로컬 호스트 :이 웹 서비스에 액세스하지 않습니다

public static void main(String[] args){ 

    String host = args[0]; 
    String hello = args[1]; 
    String world = args[2]; 

    System.out.println(hello+" "+world); 

} 
+0

8000/SOA/WSDL 안녕하세요 세계, 그것은 단지 메소드를 구현 . – DrKaoliN