2016-09-30 9 views
1

私はwcfサービスと顧客の挿入または更新のリクエストを送信する角度アプリを持っています。 wcfサービスは要求を受け取り、適切なメソッドを呼び出しますが、メソッドのパラメータ値はnullです。 WebMessageBodyStyleをBareに変更しようとしましたが、メソッド自体は呼び出されません。私は[FromBody]属性で、オブジェクトと文字列パラメータの両方で試しました。どちらもメソッドに入りますが、パラメータ値はまだnullです。私はアイデアがありません。ヘルプをいただければ幸いです。wcfメソッドのjsonをdeserializeメソッドのパラメータがnullです

 [ServiceContract] 
    public interface ICustomerService 
    { 
     [WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.WrappedRequest, 
      RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)] 
     [OperationContract] 
     bool InsertOrUpdateCustomer(Customer customer); 

    } 
    [DataContract] 
    public class Customer 
    { 
     [DataMember] 
     public CustomerType Type { get; set; } 
     [DataMember] 
     public String Name { get; set; } 
     [DataMember] 
     public string Email { get; set; } 
     [DataMember] 
     public String Password { get; set; } 
     [DataMember] 
     public String NewPassword { get; set; } 
     [DataMember] 
     public virtual IList<Address> Addresses { get; set; } 
     [DataMember] 
     public virtual IList<CustomerLicense> CustomerLicenses { get; set; } 
    } 

    public enum CustomerType 
    { 
     Organizational = 0, 
     Individual = 1 
    } 
    [DataContract] 
    public class Address 
    { 
    } 
    [DataContract] 
    public class CustomerLicense 
    { 
    } 

    public class Service : ICustomerService 
    { 

     public bool InsertOrUpdateCustomer(Customer customer) 
     { 
      try 
      { 
       if (customer == null) 
        throw new ArgumentNullException(nameof(customer)); 
       //do work for insert/update 
       return true; 
      } 
      catch (Exception ex) 
      { 
       System.Diagnostics.Debug.WriteLine(ex.Message); 
       return false; 
      } 
     } 
    } 

私は、WCFサービスに送信された要求角度アプリ持た下:

POST http://localhost:49258/CustomerSecurityService.svc/CustomerSecurityService/InsertOrUpdateCustomer HTTP/1.1 
 
Host: localhost:49258 
 
Connection: keep-alive 
 
Content-Length: 109 
 
Accept: text/html,application/xhtml+xml,application/json,application/xml;q=0.9,*/*;q=0.8 
 
Origin: http://localhost:9342 
 
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.116 Safari/537.36 
 
Authorization: Basic c2FtZXByb2JsZW06bW9yZWNvZGU= 
 
Content-Type: application/json; charset=UTF-8 
 
Referer: http://localhost:9342/index.html/ 
 
Accept-Encoding: gzip, deflate 
 
Accept-Language: en-GB,en-US;q=0.8,en;q=0.6 
 

 
{"Password":"passwordtest","Name":"nametest","NewPassword":"newPasswordTest","Type":1,"Email":"[email protected]"}

答えて

0

をあなたがラップされたリクエストを使用している、のようなあなたのJSONをパック:

{"customer":{"Password":"passwordtest","Name":"nametest","NewPassword":"newPasswordTest","Type":1,"Email":"[email protected]", "Addresses":"null", "CustomerLicenses":"null" }} 
関連する問題