私は wcf でアプリケーションを作成し、残りは Type Post he return Method not allowed での私の操作に問題があります。これは私の操作です
[WebInvoke(Method = "POST", UriTemplate = "newContact", ResponseFormat = WebMessageFormat.Json)]
[AuthorizedMethod]
bool CreateContact(string jsonstring);
このページでは、タイプ文字列をjsonに変換します
public bool CreateContact(string jsonstring)
{
Dictionary<string, string> values = JsonConvert.DeserializeObject<Dictionary<string, string>>(jsonstring);
log();
return dispatcher.CreateContact(values);
これが私のサービスです
<system.serviceModel>
<services>
<service behaviorConfiguration="Default" name="Mobility.SolutionService.AppService">
<host>
<baseAddresses>
<add baseAddress="https://localhost:443/B2M/"/>
</baseAddresses>
</host>
<endpoint address="" binding="webHttpBinding" bindingConfiguration="crossDomain"
contract="Mobility.SolutionService.IAppService" behaviorConfiguration="Web"/>
</service>
</services>
<bindings>
<webHttpBinding>
<binding name="crossDomain">
<security mode="Transport">
<transport clientCredentialType="Basic" >
</transport>
</security>
</binding>
</webHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="Default">
<serviceDebug includeExceptionDetailInFaults="true"/>
<serviceMetadata httpsGetEnabled="true" />
<serviceCredentials>
<userNameAuthentication userNamePasswordValidationMode="Custom"
customUserNamePasswordValidatorType="Mobility.SolutionService.CustomUserNamePasswordValidator, Mobility.SolutionService"/>
<serviceCertificate findValue="CN=AuthorityName"/>
</serviceCredentials>
<serviceAuthorization principalPermissionMode="Custom">
<authorizationPolicies>
<add policyType="Mobility.SolutionService.CustomAuthorizationPolicy, Mobility.SolutionService"/>
</authorizationPolicies>
</serviceAuthorization>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="Web">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
そして、jsでデータを送信します
function CreateClient(button){
var strN = document.getElementById('nom').value;
var str1 = document.getElementById('Phone').value;
var str2 = document.getElementById('Address').value;
var str10 = document.getElementById('Credit_Limit_LCY').value;
var dict = [];
dict.push(
{
key:"nom",
value: strN
},
{
key:"Phone",
value:str1
},
{
key: "Address",
value:str2
},
{
key:"Credit_Limit_LCY",
value:str10
}
);
var Mydata=JSON.stringify(dict);
$.mobile.showPageLoadingMsg();
var geturl;
geturl =$.ajax({
url:"https://10.0.2.2:443/B2M/newContact/",
data:Mydata,
contentType:"application/json; charset=utf-8",
dataType:"json",
timeout:10000000,
cache:false,
type:'POST',
beforeSend : function(req) {
req.setRequestHeader('Authorization',
make_base_auth (val1,val2));
},
error:function(XMLHttpRequest,textStatus, errorThrown) {
$.mobile.hidePageLoadingMsg();
alert("Error status :"+textStatus);
alert("Error type :"+errorThrown);
alert("Error message :"+XMLHttpRequest.responseXML);
},
success:function(data) {
alert("success");
$.mobile.hidePageLoadingMsg();
$.mobile.changePage("contact.html", "fade");
}
});
}
助けてくれませんか ありがとう