18

これが私のコードです

import org.ksoap2.*;
import org.ksoap2.serialization.*;
import org.ksoap2.transport.*;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class ksop2test extends Activity {
 /** Called when the activity is first created. */


 private static final String METHOD_NAME = "SayHello";
// private static final String METHOD_NAME = "HelloWorld";

 private static final String NAMESPACE = "http://tempuri.org";
// private static final String NAMESPACE = "http://tempuri.org";

 private static final String URL = "http://192.168.0.2:8080/HelloWCF/Service1.svc";
// private static final String URL = "http://192.168.0.2:8080/webservice1/Service1.asmx";

 final String SOAP_ACTION = "http://tempuri.org/IService1/SayHello";
// final String SOAP_ACTION = "http://tempuri.org/HelloWorld";
 TextView tv;
 StringBuilder sb;



 @Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  tv = new TextView(this);
  sb = new StringBuilder();
  call();
  tv.setText(sb.toString());
  setContentView(tv);
 }

 public void call() {
  try {

   SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

   request.addProperty("name", "Qing");

   SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
     SoapEnvelope.VER11);
   envelope.dotNet = true;
   envelope.setOutputSoapObject(request);


   HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
   androidHttpTransport.call(SOAP_ACTION, envelope);
   sb.append(envelope.toString() + "\n");//cannot get the xml request send
   SoapPrimitive result = (SoapPrimitive)envelope.getResponse();

   //to get the data
   String resultData = result.toString();
   // 0 is the first object of data 


   sb.append(resultData + "\n");
  } catch (Exception e) {
   sb.append("Error:\n" + e.getMessage() + "\n");
  }

 }

}

.asmxサービスに正常にアクセスできますが、wcfサービスを呼び出そうとすると、仮想マシンは次のように表示します。エラー:expected:END_TAG { http://schemas.xmlsoap.org/soap/envelope/ } Body(position:END_TAGhttp:/ /schemas.xmlsoap.org/soap/envelope/}s:Fault>@1:712 in java.io.InputStreamReader@43ba6798

リクエストが送信するものを印刷するにはどうすればよいですか?

これがwcfwsdlです:

<wsdl:definitions name="Service1" targetNamespace="http://tempuri.org/">

<wsdl:types>
  <xsd:schema targetNamespace="http://tempuri.org/Imports">
  <xsd:import schemaLocation="http://para-bj.para.local:8080/HelloWCF/Service1.svc?xsd=xsd0" namespace="http://tempuri.org/"/>
  <xsd:import schemaLocation="http://para-bj.para.local:8080/HelloWCF/Service1.svc?xsd=xsd1" namespace="http://schemas.microsoft.com/2003/10/Serialization/"/>
  </xsd:schema>
</wsdl:types>

<wsdl:message name="IService1_SayHello_InputMessage">
  <wsdl:part name="parameters" element="tns:SayHello"/>
</wsdl:message>

<wsdl:message name="IService1_SayHello_OutputMessage">
  <wsdl:part name="parameters" element="tns:SayHelloResponse"/>
</wsdl:message>

<wsdl:portType name="IService1">
  <wsdl:operation name="SayHello">
    <wsdl:input wsaw:Action="http://tempuri.org/IService1/SayHello" message="tns:IService1_SayHello_InputMessage"/>
    <wsdl:output wsaw:Action="http://tempuri.org/IService1/SayHelloResponse" message="tns:IService1_SayHello_OutputMessage"/>
  </wsdl:operation>
</wsdl:portType>

<wsdl:binding name="BasicHttpBinding_IService1" type="tns:IService1">
  <soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>

  <wsdl:operation name="SayHello">
   <soap:operation soapAction="http://tempuri.org/IService1/SayHello" style="document"/>

     <wsdl:input>
       <soap:body use="literal"/>
     </wsdl:input> 
     <wsdl:output>
       <soap:body use="literal"/>
     </wsdl:output>
  </wsdl:operation>
</wsdl:binding>

<wsdl:service name="Service1">

  <wsdl:port name="BasicHttpBinding_IService1" binding="tns:BasicHttpBinding_IService1">
    <soap:address location="http://para-bj.para.local:8080/HelloWCF/Service1.svc"/>
  </wsdl:port>
</wsdl:service>

</wsdl:definitions>

<xsd:schema>タグで使用し<wsdl:types> 、asmxは<s:schema>タグで使用し<wsdl:types> ます違いは何ですか?

4

4 に答える 4

19

名前空間が最後に「/」を逃したため、最終的に機能するようになりました。

以下は私のコードです

package cn.qing.ksop2test;


import java.io.Writer;

import org.ksoap2.*;
import org.ksoap2.serialization.*;
import org.ksoap2.transport.*;
import org.xmlpull.v1.XmlSerializer;

import android.app.Activity;
import android.os.Bundle;
import android.util.Xml;
import android.widget.TextView;

public class ksop2test extends Activity {
/** Called when the activity is first created. */


private static final String METHOD_NAME = "HelloWorldRequest";
//  private static final String METHOD_NAME = "HelloWorld";

private static final String NAMESPACE = "http://tempuri.org/";
//  private static final String NAMESPACE = "http://tempuri.org";

private static final String URL = "http://192.168.0.2:8080/HelloWCF/Service1.svc";
//  private static final String URL = "http://192.168.0.2:8080/webservice1  /Service1.asmx";

final String SOAP_ACTION = "http://tempuri.org/IService1/HelloWorld";
//  final String SOAP_ACTION = "http://tempuri.org/HelloWorld";
TextView tv;
StringBuilder sb;
private XmlSerializer writer;



@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    tv = new TextView(this);
    sb = new StringBuilder();
    call();
    tv.setText(sb.toString());
    setContentView(tv);
}

public void call() {
    try {

        SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

        request.addProperty("Name", "Qing");

        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
                SoapEnvelope.VER11);
        envelope.dotNet = true;
        envelope.setOutputSoapObject(request);


        HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
        androidHttpTransport.call(SOAP_ACTION, envelope);
        SoapPrimitive result = (SoapPrimitive)envelope.getResponse();

        //to get the data
        String resultData = result.toString();
        // 0 is the first object of data 


        sb.append(resultData + "\n");
        } catch (Exception e) {
        sb.append("Error:\n" + e.getMessage() + "\n");
        }

    }

}
于 2010-04-09T06:28:29.040 に答える
1

私は使用しています

private static final String SOAP_ACTION = "http://tempuri.org/IContact/GetContactCount";
private static final String METHOD_NAME = "GetContactCount";
private static final String NAMESPACE = "http://tempuri.org/";
private static final String URL = "http://xxx.xxx.com/Contacts/ContactsService.Contacts.svc";

したがって、SOAP アクションに問題がある可能性があります。

また、メソッド名のスペルは正しいですか、つまり AuthenticatdUser ですか?

于 2010-09-04T09:13:18.110 に答える
0

Qing さん、回答ありがとうございます。WCF サービスを呼び出すのに本当に役立ちます。

outputSoapObject をエンベロープに設定した後、Web サービスから単純な出力と複雑な出力を取得するために、この修正を追加したいと思います。間違っている場合は修正してください。

envelope.setOutputSoapObject(requestSoapObject);

        // if its dotnet web service then make it true
        if (isDotNetWebService)
            envelope.dotNet = true;

        HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
        androidHttpTransport.call(NAMESPACE + methodName, envelope);

        if (useBodyIn) // use bodyIn if service method returns string/int
                        // etc
        {
            /* Gives output from webservice */
            responseSoapObject = (SoapObject) envelope.bodyIn;
        } else // use getResponse() if service method returns objects or
                // array
        {
            /* Gives output from webservice */
            responseSoapObject = (SoapObject) envelope.getResponse();
        } 
于 2013-10-14T06:16:39.430 に答える
0

「理論」では、基本的な http バインディングを使用する wcf と asmx は同じように動作するはずです。

WCF サービスの構成方法に関係している可能性があります。

クライアントで TransferMode Streamed を構成し、サーバーで Buffered を構成すると、同様の問題が発生します。これがあなたのケースに関連しているかどうかはわかりませんが。

于 2010-04-07T21:17:47.683 に答える