2017-02-03 1 views
0

Java、CSharp、PythonクライアントからJava Webサービスに接続する必要があるため、Protobufオブジェクトを直列化に使用しています。私は、ファイルへのJavaいるProtobufバイトを書く場合バイト配列パラメータでsudsとprotobufを使用してPythonからJava Webサービスを実行する際の問題

、私は単純に実行してPythonで読むことができています:

temp = time_series_request_meta_data.SerializeToString() 
f = open("../../../../resources/test.protoBytes", "wb") 
f.write(temp) 
f.close() 

している場合:私は、ファイルへのPythonから書く場合

f = open("../../../../resources/test.protoBytes", "rb") 
java_deserialized = timeSeriesRequests.TimeSeriesRequestMetaData() 
java_deserialized.ParseFromString(f.read()) 

Javaでの読書に問題はありません。私は休憩を置くことができます

public byte[] addValueToTimeSeries(byte[] protoRequestMetaData, byte[] protoRequest) 

client = Client('http://localhost:5750/ws/protoservice?wsdl', plugins=[LogPlugin()]) 
response = client.service.addValueToTimeSeries(data.SerializeToString(), otherData.SerializeToString()) 

サーバ側のメソッドシグネチャを:私は実行して、Javaで[]バイトとるSOAPサービスを呼び出そうと泡-jurko 0.6を使用して

サーバー側の呼び出しでポイントし、メソッドが呼び出されますが、バイト配列文字列が正しくありません。

これは、クライアントから送信されました:

b'<?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns0="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://services.common.ddp/"><SOAP-ENV:Header/><ns0:Body><ns1:addValueToTimeSeries><arg0>b&apos;\\n\\x06ddp_sm\\x12\\x0btest-domain\\x1a\\tlocalhost&apos;</arg0><arg1>b&apos;\\n\\x06\\x08\\x81\\x9c\\x92\\xa5\\x05\\x12\\x06\\x08\\x81\\x9c\\x92\\xa5\\x05\\x1a\\x04Test&quot;\\x05Test2*&lt;\\n/type.googleapis.com/google.protobuf.DoubleValue\\x12\\t\\t\\x00\\x00\\x00\\x00\\x00\\[email protected]&apos;</arg1></ns1:addValueToTimeSeries></ns0:Body></SOAP-ENV:Envelope>' 

私が代わりにこれをやってみました:

response = client.service.addValueToTimeSeries(list(data.SerializeToString()), list(otherData.SerializeToString()) 

と私はクライアントに正しいバイト配列が作成されていることがわかり、今ですることができますサーバー側では、バイト配列は空です。

これは(泡ログインから)Pythonクライアントから送信されます。

b'<?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns0="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://services.common.ddp/"><SOAP-ENV:Header/><ns0:Body><ns1:addValueToTimeSeries><arg0>10</arg0><arg0>6</arg0><arg0>100</arg0><arg0>100</arg0><arg0>112</arg0><arg0>95</arg0><arg0>115</arg0><arg0>109</arg0><arg0>18</arg0><arg0>11</arg0><arg0>116</arg0><arg0>101</arg0><arg0>115</arg0><arg0>116</arg0><arg0>45</arg0><arg0>100</arg0><arg0>111</arg0><arg0>109</arg0><arg0>97</arg0><arg0>105</arg0><arg0>110</arg0><arg0>26</arg0><arg0>9</arg0><arg0>108</arg0><arg0>111</arg0><arg0>99</arg0><arg0>97</arg0><arg0>108</arg0><arg0>104</arg0><arg0>111</arg0><arg0>115</arg0><arg0>116</arg0><arg1>10</arg1><arg1>6</arg1><arg1>8</arg1><arg1>129</arg1><arg1>156</arg1><arg1>146</arg1><arg1>165</arg1><arg1>5</arg1><arg1>18</arg1><arg1>6</arg1><arg1>8</arg1><arg1>129</arg1><arg1>156</arg1><arg1>146</arg1><arg1>165</arg1><arg1>5</arg1><arg1>26</arg1><arg1>4</arg1><arg1>84</arg1><arg1>101</arg1><arg1>115</arg1><arg1>116</arg1><arg1>34</arg1><arg1>5</arg1><arg1>84</arg1><arg1>101</arg1><arg1>115</arg1><arg1>116</arg1><arg1>50</arg1><arg1>42</arg1><arg1>60</arg1><arg1>10</arg1><arg1>47</arg1><arg1>116</arg1><arg1>121</arg1><arg1>112</arg1><arg1>101</arg1><arg1>46</arg1><arg1>103</arg1><arg1>111</arg1><arg1>111</arg1><arg1>103</arg1><arg1>108</arg1><arg1>101</arg1><arg1>97</arg1><arg1>112</arg1><arg1>105</arg1><arg1>115</arg1><arg1>46</arg1><arg1>99</arg1><arg1>111</arg1><arg1>109</arg1><arg1>47</arg1><arg1>103</arg1><arg1>111</arg1><arg1>111</arg1><arg1>103</arg1><arg1>108</arg1><arg1>101</arg1><arg1>46</arg1><arg1>112</arg1><arg1>114</arg1><arg1>111</arg1><arg1>116</arg1><arg1>111</arg1><arg1>98</arg1><arg1>117</arg1><arg1>102</arg1><arg1>46</arg1><arg1>68</arg1><arg1>111</arg1><arg1>117</arg1><arg1>98</arg1><arg1>108</arg1><arg1>101</arg1><arg1>86</arg1><arg1>97</arg1><arg1>108</arg1><arg1>117</arg1><arg1>101</arg1><arg1>18</arg1><arg1>9</arg1><arg1>9</arg1><arg1>0</arg1><arg1>0</arg1><arg1>0</arg1><arg1>0</arg1><arg1>0</arg1><arg1>0</arg1><arg1>89</arg1><arg1>64</arg1></ns1:addValueToTimeSeries></ns0:Body></SOAP-ENV:Envelope>' 

は、誰かが私が何をする必要があるか提案してくださいことはできますか?

これは私の最初のPythonアプリケーションです。その答えが簡単なのであれば、私は驚かないでしょう。これはファイル経由では動作しますが、Webサービス全体では失敗します。

私は小さなサンプルWebサービスを作成しましたが、zipをアップロードすることはできません。

私はこのようなstruct.unpack使用して試してみました:

struct.unpack('B' * len(serialized_request), serialized_request) 

これは正しいint型の配列を返しますが、空の配列として、Webサービスに渡されます。

以下

は、WSDLの内容です:

<definitions targetNamespace="http://examples.com/" name="com.examples.ExampleWebService"><types><xsd:schema><xsd:import namespace="http://examples.com/" schemaLocation="http://localhost:5750/ws/examplewebservice?xsd=1"/></xsd:schema></types><message name="addRequest"><part name="parameters" element="tns:addRequest"/></message><message name="addRequestResponse"><part name="parameters" element="tns:addRequestResponse"/></message><portType name="ExampleWebServiceContract"><operation name="addRequest"><input wsam:Action="http://examples.com/ExampleWebServiceContract/addRequestRequest" message="tns:addRequest"/><output wsam:Action="http://examples.com/ExampleWebServiceContract/addRequestResponse" message="tns:addRequestResponse"/></operation></portType><binding name="ExampleWebServicePortBinding" type="tns:ExampleWebServiceContract"><soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/><operation name="addRequest"><soap:operation soapAction=""/><input><soap:body use="literal"/></input><output><soap:body use="literal"/></output></operation></binding><service name="com.examples.ExampleWebService"><port name="ExampleWebServicePort" binding="tns:ExampleWebServicePortBinding"><soap:address location="http://localhost:5750/ws/examplewebservice"/></port></service></definitions> 
+0

私はJavaでプログラミングされたことはありませんでしたが、Pythonでの私の経験から、SOAPは***の痛みです。 WSDLがないと、Python側からサービスを呼び出す方法の問題点を教えにくくなります。 –

+0

'データ 'はどのようなタイプですか?多分 'SerializeToString'は問題ですか?不要なエンコーディングがそこにあるように見えます。 –

+0

V Stoykov - 私が作成したWebサービスの例として、今wsdlの内容を追加しました。 – Chill

答えて

0

多くの組み合わせを試した後、私は次の手順を実行する必要がありいるProtobufを使ってPythonから泡にバイト配列を渡すことが見つかりました:

  1. ProtobufオブジェクトのSerializeToString()を呼び出します。
  2. バイトの文字列表現をbase64.b64encodeに渡します。
  3. 結果の上でdecode()を呼び出すと、開始時にb 'を、終了時にASCIIストリッピングを戻します。
関連する問題