Being new to WCF, I am trying to figure out the proper configuration to return a JSON object from a WCF service.
The result I am getting is (viewed in firebug):
{"TestServiceResult": "{\"AccountID\":999999,\"CardNumber\":555555,\"AccountBalance\":999.99,\"GivenName\":\"Ben\",\"FamilyName\":\"Rosniak\"}"}
The part I am interested in is one long string and not the JSON object I am after.
The only configuration regarding the service is (the project was started by someone else):
<!-- Added for Mobile Pay Service-->
<behaviors>
<serviceBehaviors>
<behavior name="MobilePayServiceBehaviour" >
<serviceDebug includeExceptionDetailInFaults="true"/>
<!--<serviceCredentials >
<userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="MobilePayService.WtfUserNamePasswordValidator, MobilePayService" />
</serviceCredentials>
<serviceAuthorization principalPermissionMode="Custom">
<authorizationPolicies>
<add policyType="MobilePayService.WtfAuthorizationPolicy, MobilePayService" />
</authorizationPolicies>
</serviceAuthorization>-->
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="WebHttpBehaviour">
<webHttp automaticFormatSelectionEnabled="false" defaultBodyStyle="Wrapped" defaultOutgoingResponseFormat="Json" helpEnabled="true" />
</behavior>
</endpointBehaviors>
</behaviors>
And the test method I am using to make sure the response gets formatted:
[WebGet(UriTemplate = "TestService/{id}/{device}/{culture}")]
public string TestService(string id, string device, string culture)
{
WCFProfileModel profileModel = new WCFProfileModel()
{
AccountID = 999999,
AccountBalance = 999.99F,
CardNumber = 555555,
GivenName = "Ben",
FamilyName = "Rosniak"
};
return profileModel;
}
Somehow the reponse is getting wrapped inside a template of some kind, and I would like know where and how this happens, but I'm not sure where to start looking for this. I would like to strip away the "TestServiceResult"
portion and only return:
{"AccountID":999999,"CardNumber":555555,"AccountBalance":999.99,"GivenName":"Ben","FamilyName":"Rosniak"}
UPDATE: I have tried following the tutorial here (updated my code to reflect this), but I get an error "saying profileModel can not be implicitly converted to a string".