2015-01-23 17 views
0

enter image description hereWCF 서비스가 null의 요청을 받아 여기에

var dataToSend = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(mi)); 

     var req = HttpWebRequest.Create("http://localhost/Service1.svc/json/MethodName"); 

     req.ContentType = "application/json"; 
     req.ContentLength = dataToSend.Length; 
     req.Method = "POST"; 
     req.GetRequestStream().Write(dataToSend, 0, dataToSend.Length); 

     var response = req.GetResponse(); 

"/ JSON"내 엔드 포인트 주소가 내 서비스는 다수의 엔드 포인트로 구성되어 있습니다. 이미지 당 여기에, 내가 보낸 요청은 서버에서 null을받는 것입니다.

요청 형식이 적절하지 않은 경우이 서비스를 호출하는 적절한 방법을 제안하십시오.

// 서비스 간 얼굴

[ServiceContract] 
public interface IService 
{ 


    [OperationContract] 
    [WebInvoke(Method="POST")] 
    Response MethodName(Request request); 
} 

// 서비스 1

public class Service1 : IService 
    { 
     public Response MethodName(Request request) 
     { 
      some logical operation.... 
     } 
    } 

// 엔드 포인트 구성 (웹 설정)

<endpoint address="json" behaviorConfiguration="jsonBehavior" 
       binding="webHttpBinding" bindingConfiguration="webHttpBindingJson" 
       name="jsonn" contract="Service1.IService" /> 

<endpoint address="xml" behaviorConfiguration="poxBehavior" binding="webHttpBinding" 
       bindingConfiguration="webHttpBindingXml" name="xmll" contract="Service1.IService" /> 

<endpointBehaviors> 
    <behavior name="jsonBehavior">   
     <enableWebScript /> 
    </behavior> 
<behavior name="poxBehavior"> 
     <enableWebScript /> 
    </behavior> 
    </endpointBehaviors> 

<webHttpBinding> 
    <binding name="webHttpBindingJson"> 
     <security mode="None" /> 
    </binding> 
    <binding name="webHttpBindingXml"> 
     <security mode="None" /> 
    </binding> 
    </webHttpBinding> 

// 요청 클래스

[DataContract] 
public class Request 
{ 
    string userMobile; 
    string otp; 

    [DataMember] 
    public string UserMobile 
    { 
     get { return userMobile; } 
     set { userMobile = value; } 
    } 
    [DataMember] 
    public string OTP 
    { 
     get { return otp; } 
     set { otp = value; } 
    } 
} 
+0

서비스가 실제로 json을 입력으로 사용합니까? 당신은 정의를 보여주지 못했습니다. – nvoigt

+0

예, 종단점 구성으로 json과 xml을 사용합니다. "WebApplication"은 "WebInvoke (Method ="POST ")입니다.

+0

인터페이스 구성은 [)] 응답 MethodName (요청 요청); –

답변

0

마지막으로 찾았습니다. 나는 이것에

<behavior name="jsonBehavior">   
     <webHttp defaultBodyStyle ="Bare"/> 
     <!--<enableWebScript />--> 
    </behavior> 

를 JSON 동작 구성의 엔드 포인트를 수정 enableWebScript를 제거했습니다. 마침내 내 코드가 작동합니다.

관련 문제