2012-06-22 2 views
3

빨간색에 대한 많은 문서가 있지만이 .svc 파일을 사용할 수 없습니다. .ASMX 파일에 문제가 없습니다. SVC 만 소비 할 수 없습니다. 아주 스트레스가 많이 .. ....! WCF 부분을 수정할 수 없습니다.안드로이드에서 WCF .SVC를 사용하는 방법

WSDL

<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" 
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" 
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" 
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" 
xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" 
xmlns:tns="http://tempuri.org/" 
xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" 
xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" 
xmlns:wsap="http://schemas.xmlsoap.org/ws/2004/08/addressing/policy" 
    xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
xmlns:msc="http://schemas.microsoft.com/ws/2005/12/wsdl/contract" 
xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" 
xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" 
xmlns:wsa10="http://www.w3.org/2005/08/addressing" 
xmlns:wsx="http://schemas.xmlsoap.org/ws/2004/09/mex" name="ValidateUser_wcf" 
targetNamespace="http://tempuri.org/"> 
<wsp:Policy wsu:Id="WSHttpBinding_IValidateUser_wcf_policy"> 
<wsp:ExactlyOne> 
<wsp:All> 
<wsaw:UsingAddressing/> 
</wsp:All> 
</wsp:ExactlyOne> 
</wsp:Policy> 
<wsdl:types> 
<xsd:schema targetNamespace="http://tempuri.org/Imports"> 
<xsd:import schemaLocation="http://URL/WebServices/validateuser.svc?xsd=xsd0" namespace="http://tempuri.org/"/> 
<xsd:import schemaLocation="http://URL/WebServices/validateuser.svc?xsd=xsd1" namespace="http://schemas.microsoft.com/2003/10/Serialization/"/> 
</xsd:schema> 
</wsdl:types> 
<wsdl:message name="IValidateUser_wcf_ValidateUser_InputMessage"> 
<wsdl:part name="parameters" element="tns:ValidateUser"/> 
</wsdl:message> 
<wsdl:message name="IValidateUser_wcf_ValidateUser_OutputMessage"> 
<wsdl:part name="parameters" element="tns:ValidateUserResponse"/> 
</wsdl:message> 
<wsdl:portType name="IValidateUser_wcf"> 
<wsdl:operation name="ValidateUser"> 
<wsdl:input wsaw:Action="http://tempuri.org/IValidateUser_wcf/ValidateUser" message="tns:IValidateUser_wcf_ValidateUser_InputMessage"/> 
<wsdl:output wsaw:Action="http://tempuri.org/IValidateUser_wcf/ValidateUserResponse" message="tns:IValidateUser_wcf_ValidateUser_OutputMessage"/> 
</wsdl:operation> 
</wsdl:portType> 
<wsdl:binding name="WSHttpBinding_IValidateUser_wcf" type="tns:IValidateUser_wcf"> 
<wsp:PolicyReference URI="#WSHttpBinding_IValidateUser_wcf_policy"/> 
<soap12:binding transport="http://schemas.xmlsoap.org/soap/http"/> 
<wsdl:operation name="ValidateUser"> 
<soap12:operation soapAction="http://tempuri.org/IValidateUser_wcf/ValidateUser" style="document"/> 
<wsdl:input> 
<soap12:body use="literal"/> 
</wsdl:input> 
<wsdl:output> 
<soap12:body use="literal"/> 
</wsdl:output> 
</wsdl:operation> 
</wsdl:binding> 
<wsdl:service name="ValidateUser_wcf"> 
<wsdl:port name="WSHttpBinding_IValidateUser_wcf" binding="tns:WSHttpBinding_IValidateUser_wcf"> 
<soap12:address location="http://URL/WebServices/validateuser.svc"/> 
<wsa10:EndpointReference> 
<wsa10:Address> 
http://URL/WebServices/validateuser.svc 
</wsa10:Address> 
</wsa10:EndpointReference> 
</wsdl:port> 
</wsdl:service> 
</wsdl:definitions> 

내 자바 # 1 : 나는 WSDL 파일과 그것을 소비하는 나의 시도를 게시 할 수 있습니다. Ksoap2에 의해

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

private static final String SOAP_ACTION_VALIDATION = "IValidateUser_wcf/ValidateUser"; 
private static final String VALIDATION_METHOD = "ValidateUser"; 
private final static String VALIDATION_URI = "http://URL/WebServices/validateuser.svc"; 

// only a1 node in the header i know, each other is unknown for me. I put them there only because i saw them in soap net client http post 
String request = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"+ 
     "<s:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:s=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:a=\"http://www.w3.org/2005/08/addressing\">" 
     + "<s:Header>" 
     //+ "<a:Action s:mustUnderstand=\"1\"> http://tempuri.org/IValidateUser_wcf/ValidateUser </a:Action>" 
     + "<a1 xmlns=\"http://xxxx.xxx/\">"+testtoken+"</a1>" 
     + "<a:MessageID> urn:uuid:c075fc4e-1e70-48f7-838b-9fa68e7aaad1 </a:MessageID>" 
     + "<ActivityId CorrelationId=\"0d4e09eb-5d09-4617-a8e1-ec99415caab5\" xmlns=\"http://schemas.microsoft.com/2004/09/ServiceModel/Diagnostics\">" 
     + "25adfad8-ab5f-474a-afe3-56941d4ad408" 
     + "</ActivityId>" 
     + "<a:ReplyTo> http://www.w3.org/2005/08/addressing/anonymous </a:ReplyTo>" 
     + "<a:To s:mustUnderstand=\"1\"> http://URL/WebServices/validateuser.svc </a:To>" 
     + "</s:Header>" 
     + "<s:Body><ValidateUser xmlns=\"http://tempuri.org/\"><username>"+username+"</username><password>"+password+"</password></ValidateUser></s:Body>" 
     + "</s:Envelope>"; 

    String result = CallWebService(VALIDATION_URI, NAMESPACE+VALIDATION_METHOD, request); 



public String CallWebService(String url, String soapAction, String envelope) { 

    final DefaultHttpClient httpClient = new DefaultHttpClient(); 
    // request parameters 
    HttpParams params = httpClient.getParams(); 
    HttpConnectionParams.setConnectionTimeout(params, 10000); 
    HttpConnectionParams.setSoTimeout(params, 15000); 
    // set parameter 
    HttpProtocolParams.setUseExpectContinue(httpClient.getParams(), true); 

    // POST the envelope 
    HttpPost httppost = new HttpPost(url); 
    // add headers 
    httppost.setHeader("soapaction", soapAction); 
    httppost.setHeader("Content-Type", "text/xml; charset=utf-8"); 

    String responseString = "Nothingggg"; 
    try { 

     // the entity holds the request 
     HttpEntity entity = new StringEntity(envelope); 
     httppost.setEntity(entity); 

     // Response handler 
     ResponseHandler<String> rh = new ResponseHandler<String>() { 
      // invoked when client receives response 
      public String handleResponse(HttpResponse response) 
        throws ClientProtocolException, IOException { 

       // get response entity 
       HttpEntity entity = response.getEntity();     

       // read the response as byte array 
       StringBuffer out = new StringBuffer(); 
       byte[] b = EntityUtils.toByteArray(entity); 

       // write the response byte array to a string buffer 
       out.append(new String(b, 0, b.length)); 
       return out.toString(); 
      } 
     }; 

     responseString = httpClient.execute(httppost, rh); 

    } catch (Exception e) { 
     e.printStackTrace(); 
     Log.d("me","Exc : "+ e.toString()); 

    } 

    // close the connection 
    httpClient.getConnectionManager().shutdown(); 
    return responseString; 
} 

내 자바 # 2 : 간단하게 나는 마이크로 소프트 닷넷 모니터 응용 프로그램과 함께, 자바에서 복제해야한다는, 원래 .NET 클라이언트에 대해 후 스니핑 HTTP의 POST 트래픽을 나올 XML을 복사 한 . 이 경우이 오류가있어 :

XmlPullParserException: unexpected type 
(position:END_DOCUMENT [email protected]:1 in 
[email protected]) 

을하지만 난 검증 XML 응용 프로그램에서 XML 문자열 요청을 넣어 괜찮아요 :

public String validateUser_WCF(String username, String password){ 

    String enctoken = TOKEN; 
    String testtoken = TestTOKEN;  

    SoapSerializationEnvelope envelope = null; 
    SoapObject request = null; 
    HttpTransportSE httpTransportSE = null; 

    try { 
     request = new SoapObject(NAMESPACE, VALIDATION_METHOD); 
     request.addProperty("username", username); 
     request.addProperty("password", password); 

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

     Element[] header = new Element[2]; 
     header[0] = new Element().createElement(NAMESPACE, "To"); 
     header[0].setName("a1");     
     header[0].addChild(Node.TEXT, VALIDATION_URI); 

     header[1] = new Element().createElement(NAMESPACE_INFOCAD, "a1");     
     header[1].addChild(Node.TEXT, testtoken); 

     envelope.headerOut = header;         

     httpTransportSE = new HttpTransportSE(VALIDATION_URI); 

     httpTransportSE.debug = true; 
     //httpTransportSE.setXmlVersionTag("<?xml version=\"1.0\" encoding=\"utf-8\"?>"); 

     httpTransportSE.call(NAMESPACE+SOAP_ACTION_VALIDATION, envelope); 

     String response = (String) envelope.getResponse(); 
     Log.i("RESPONSE", response); 
     return response; 

     } catch (Exception e) { 
      // TODO: handle exception 
      e.printStackTrace(); 
     }finally{ 
      Log.i(getClass().getSimpleName(),"requestDump : "+httpTransportSE.requestDump); 
      Log.i(getClass().getSimpleName(),"responseDump : "+httpTransportSE.responseDump); 
     } 

내가 정말 누군가가 나를 도울 수 있기를 바랍니다. 임은 죽은 지점에 도착했습니다 ....

+0

내가 왜 말도없이 왜 사람들 unrate 질문을 이해 해달라고. 나는 내 질문에 분명하다고 생각한다 – kinghomer

+0

순간에, 나는 basicHTTPbinding을 설정하도록 요청했고, 나의 행운을 위해서 그들은 바인딩을 변경했다. 이제는 모두 잘 작동하지만 질문은 항상 WS 바인딩으로 해결되지 않습니다 .... – kinghomer

+0

질문에 대한 해결책을 얻었습니까? 그렇다면 도와주세요. 나도 같은 문제로 고생했다. http://stackoverflow.com/questions/12928759/android-with-wcf-web-service-using-ksoap2-error-soapfault-faultcode-ainte –

답변

2

(WCF 바인딩은은 BasicHttpBinding 수있다 그렇지 않으면 작동하지 않습니다) :

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

private static final String SOAP_ACTION_VALIDATION = "IValidateUser_wcf/ValidateUser"; 
private static final String VALIDATION_METHOD = "ValidateUser"; 

public boolean validateUser_WCF(String username, String password){ 

    SoapSerializationEnvelope envelope = null; 
    SoapObject request = null; 
    HttpTransportSE httpTransportSE = null; 

    try { 
     request = new SoapObject(NAMESPACE, VALIDATION_METHOD); 
     request.addProperty("username", username); 
     request.addProperty("password", password); 

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

     //////////////////////////////        
     // here you can add a HEADER element if you want 
     Element[] header = new Element[1]; 

     header[0] = new Element().createElement(NAMESPACE_INFOCAD, "a1");     
     header[0].addChild(Node.TEXT, "HeaderTextContent"); 

     envelope.headerOut = header; 
     //////////////////////////////        

     httpTransportSE = new HttpTransportSE(URL+VALIDATION_URI, 10*10000); // second parameter is timeout 
     httpTransportSE.debug = true; 
     httpTransportSE.setXmlVersionTag("<?xml version=\"1.0\" encoding=\"utf-8\"?>"); 
     httpTransportSE.call(NAMESPACE+SOAP_ACTION_VALIDATION, envelope); 

     // if response is a simple text result, you can call SoapPrimitive, if not, you have to call SoapObject result and navigate in response's tree like an xml file 
     SoapPrimitive result = (SoapPrimitive)envelope.getResponse(); 

     //To get the data. 
     String textResult = result.toString(); 
     Log.i("textResult", textResult); 

     return true; 

    } catch (Exception e) { 
     // TODO: handle exception 
     e.printStackTrace(); 
    }finally{ 
       // here you can see in LOG what is request you send and what is response received 
       Log.i(getClass().getSimpleName(),"requestDump : "+httpTransportSE.requestDump); 
       Log.i(getClass().getSimpleName(),"responseDump : "+httpTransportSE.responseDump); 
    } 

    return false; 
} 
+0

내가 XML로 매개 변수 중 하나를 보낼 수 있습니까? –

+0

xml? 어쩌면 나는 당신의 질문을 이해하지 못했을 것입니다. SoapSerializationEnvelope 개체는 이미 xml을 작성합니다. 나에게 예제 pls – kinghomer

+0

을 주면 XML을 만들지 만, 내 wcf 서비스 메서드는'Methodname (strinputXML, strOutoutXML)'과 같다. 그렇다면이 strInputXml에 xml을 구축하는 비누 객체를 어떻게 설정할 수 있습니까? –

2

WCF 부분을 제어 할 수 있습니까?

가장 쉬운 방법은 WCF bingding을 업데이트하는 것입니다. 현재 그것은 WSHttpBinding입니다. 바인딩은 * .asmx보다 더 복잡합니다.

바인딩이 basicHttpBinding 인 엔드 포인트를 게시 할 수 있는지 확인하십시오.

http://msdn.microsoft.com/en-us/library/ms731361.aspx

바인딩이 .asmx *과 호환되며 당신은 단지 그것을 소비하는 자바 코드에서 URL을 업데이트해야 할 것이다.

나 자신에 의해 해결
+0

WCF를 수정할 수 없습니다. 오직 소비하려고합니다. 그건 그렇고, 당신의 시간에 대한 – kinghomer

관련 문제