호출 할 WebHttpBinding WCF 서비스가 있습니다. 내 첫 번째 POST 메서드는 개체를 올바르게 보내지 만 POST 메서드에 대한 후속 호출은 개체에 대해 null을 전달합니다.WCF 호출 Null 매개 변수 전달
<system.serviceModel>
<bindings>
<webHttpBinding>
<binding name="WebHttpBindingConfig"
openTimeout="00:05:00"
sendTimeout="00:05:00"
maxBufferSize="65536000"
maxBufferPoolSize="52428800"
maxReceivedMessageSize="65536000"
transferMode="Buffered">
<readerQuotas maxDepth="32"
maxStringContentLength="65536000"
maxArrayLength="16384"
maxBytesPerRead="4096"
maxNameTableCharCount="16384" />
<security>
<transport />
</security>
</binding>
</webHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="Services.ServiceBehavior"
name="Services.MyDtoService">
<endpoint address=""
behaviorConfiguration="HttpBehavior"
binding="webHttpBinding"
name="Services.MyDtoService"
contract="ServiceInterfaces.IMyDtoService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="Services.ServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="HttpBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
그리고 마지막으로 내 클라이언트 코드가 전화를 걸 : 여기
[ServiceContract]
public interface IMyDtoService
{
[OperationContract]
[WebInvoke(Method = "GET", BodyStyle = WebMessageBodyStyle.Bare, ResponseFormat = WebMessageFormat.Json)]
List<ObjectDTO> LoadById(string value);
[OperationContract]
[WebInvoke(Method = "GET", BodyStyle = WebMessageBodyStyle.Bare, ResponseFormat = WebMessageFormat.Json)]
List<ObjectDTO> Load(string field, string value);
[OperationContract]
[WebInvoke(Method="GET", BodyStyle = WebMessageBodyStyle.Bare, ResponseFormat = WebMessageFormat.Json)]
List<ObjectDTO> LoadAll();
[OperationContract(Name = "InsertSingle")]
[WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json)]
ObjectDTO Insert(ObjectDTO objectDto);
[OperationContract(Name = "UpdateSingle")]
[WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json)]
ObjectDTO Update(ObjectDTO objectDto);
[OperationContract(Name = "DeleteSingle")]
[WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json)]
ObjectDTO Delete(ObjectDTO objectDto);
}
내 서버 구성입니다 : 여기
public void Update(ObjectDTO objectDTO)
{
string token = WebOperationContext.Current != null ? WebOperationContext.Current.IncomingRequest.Headers["token"] : string.Empty;
//Authentication
bool isUserAuthenticatedResult = IsUserAuthenticated(ref token);
if (!isUserAuthenticatedResult)
return null;
//Perform service action
MyDtoManager = new MyDtoManager();
objectDTO = MyDtoManager.Update(objectDTO);
return objectDTO;
}
내 서비스 계약입니다 : 여기
내 서비스 :
IMyDtoService myDtoService = new WebChannelFactory<IMyDtoService>(BindingConfig, new Uri("http://localhost:8080/MyDtoService.svc")).CreateChannel();
using (new OperationContextScope((IClientChannel)myDtoService))
{
if (WebOperationContext.Current != null)
WebOperationContext.Current.OutgoingRequest.Headers.Add("token", tokenResult.Result);
ObjectDTO insertResult = ipAddressService.Insert(new ObjectDTO
{ ObjectGuid = Guid.NewGuid(),
IsAllow = true,
Identifier = 1,
IdentifierType = 0,
StartIpAddress = "192.168.0.1"
});
List<ObjectDTO> loadByIdResult1 = myDtoService.LoadById(insertResult.ObjectGuid.ToString());
Console.WriteLine("Insert Found: " + loadByIdResult1.Count);
insertResult.IsAllow = false;
ObjectDTO updateResult = ipAddressService.Update(insertResult);
}
내 클라이언트 코드에서 내 WCF 서비스를 호출하고 삽입 메서드가 완벽하게 작동하며 내 데이터베이스에서 영구 객체를 볼 수 있음을 알 수 있습니다. 그러나 업데이트시 ObjectDTO 매개 변수는 null입니다. 기존 객체를로드하고 업데이트를 수행하면 완벽하게 작동합니다. POST 메서드를 사용하여 WCF 서비스를 이후에 호출 할 때 문제가되는 것으로 보입니다. GET 메서드에이 문제가 없습니다.
, 몇 가지 테스트를 수행. 내 Update 메서드가 게시 된 예제에 그대로있는 경우 Update 메서드는 ObjectDTO 매개 변수에 null 값을 가져옵니다. 왜 그 이유를 설명 할 수 있습니까? – Brandon