2012-07-13 7 views
1

이상한 행동 :WCF 나는 웹 서비스 소비 때이있어

계약 'IServices'운영 '로그인'어떤 래퍼 요소없이 직렬화 여러 요청 본문 매개 변수를 지정합니다. 최대 하나의 본문 매개 변수는 래퍼 요소없이 직렬화 할 수 있습니다. 여분의 본문 매개 변수를 제거하거나 WebGetAttribute/WebInvokeAttribute의 BodyStyle 속성을 Wrapped로 설정하십시오.

내가 좋아하는 인터페이스 모양 사용하십시오이 될 것입니다

namespace DreamServices 
{ 
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService1" in both code and config file together. 
    [ServiceContract] 
    public interface IServices 
    { 
     [OperationContract] 
     [WebInvoke(Method = "GET", 
     ResponseFormat = WebMessageFormat.Json, 

     BodyStyle = WebMessageBodyStyle.Wrapped, 

     UriTemplate = "LogIn/{username}/{password}")] 
     string Login(string username, string password); 

     [OperationContract] 
     [WebInvoke(
      Method = "GET", 
      ResponseFormat = WebMessageFormat.Json, 
      BodyStyle = WebMessageBodyStyle.Wrapped, 
      UriTemplate = "WaletTotalAmount/{userid}")] 
     double? WaletTotalAmount(string userid); 

     [OperationContract] 
     [WebInvoke(
      Method = "GET", 
      ResponseFormat = WebMessageFormat.Json, 
      BodyStyle = WebMessageBodyStyle.Wrapped, 
      UriTemplate = "UserService/{userid}")] 
     IList<UserServiceses> UserService(string userid); 

     [OperationContract] 
     [WebInvoke(Method = "POST", 
      ResponseFormat = WebMessageFormat.Json, 
      RequestFormat = WebMessageFormat.Json, 
      BodyStyle = WebMessageBodyStyle.Wrapped, 
      UriTemplate = "InsertUpdateWallet/{userid}/{Amount}/{ComissionAmount}")] 
     void InsertUpdateWallet(string userid, string Amount, string ComissionAmount); 

    } 
} 

을하고 난 후, 나는 내 사이트에 웹 참조를 추가를 호스팅하고 그러한에서 web.config를 수정

<system.serviceModel> 

    <behaviors> 
     <endpointBehaviors> 
     <behavior name="web"> 
      <webHttp /> 
      <dataContractSerializer maxItemsInObjectGraph="2147483647"/> 
     </behavior> 
     </endpointBehaviors> 
     <serviceBehaviors> 
     <behavior> 
      <dataContractSerializer maxItemsInObjectGraph="2147483647" /> 
      <serviceMetadata httpGetEnabled="true" /> 
      <serviceDebug includeExceptionDetailInFaults="true" /> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    <bindings> 
     <webHttpBinding> 
     <binding name="defaultRest"> 
      <readerQuotas maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxDepth="64" maxNameTableCharCount="2147483647" /> 
      <security mode="None" /> 
     </binding> 
     </webHttpBinding> 
    </bindings> 

    <client> 
     <endpoint address="http://localhost:1381/PMAHost/Service.svc" binding="webHttpBinding" contract="ServiceReference.IServices" behaviorConfiguration="web"/> 
    </client> 

    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" /> 
    </system.serviceModel> 

같은 어떤 생각이 오류를 해결하는 방법?

+0

이러한 속성이 꾸미는 메소드의 서명을 표시하십시오. –

+0

ok public string login (string userid); – AMH

+0

public void InsertUpdateWallet (string userid, string amount) – AMH

답변

0

처음에는 로그인을 위해 GET 작업을 사용하는 이유를 모르겠지만 POST를 올바르게 사용해야합니까? 다음은 UriTemplate에 두 개의 매개 변수를 정의했지만 메서드에는 하나만 포함되어 있습니다. 나는 매개 변수로 클래스를 사용하고 문자열을 반환하는 대신 모델을 반환 할 수있는 방법을 제안합니다.

public class LoginModel 
{ 
    public string username { get; set; } 
    public string password { get; set; } 
} 

public class Result 
{ 
    public bool success { get; set; } 
    public string error { get; set; } 
} 

[WebInvoke(Method = "POST", 
RequestFormat = WebMessageFormat.Json, 
ResponseFormat = WebMessageFormat.Json, 
UriTemplate = "/LogIn")] 
public Result login(LoginModel loginModel) 
+0

하지만 안드로이드 에서이 웹 서비스를 사용하고 매우 잘 작동, 당신은 asp.net에서 어떻게 클라이언트 프록시 에이 속성을 추가 할 http://stackoverflow.com/questions/4346554/wcf- service-proxy-throws-exception-more-than-one-parameter-of-oper – AMH

+0

오류가 모든 메소드에서 반복됨 – AMH