だから私はこれで私の髪を引き出しています。環境:ASP.net WebフォームC#2008. 私はすでにthisソリューションを提供しています。 次のようなasmx webserviceを作成しました(コードを参照)、私はブラウザ経由でアクセスしようとしています。基本的に私がhttp://localhost/service.asmxを指しているとき、それはうまく動作し、利用可能な操作やものを見ることができます。私はまた、URL http://localhost/service.asmx?op=MethodNameで詳細に操作を見ることができますが、実際にサービスを試したり呼び出したりするときに問題が発生します。私はhttp://localhost/service.asmx/MethodNameが見つかりません。 何が間違っている可能性がありますか?asmxサービスの操作結果が文書に見つかりません
[WebService(Namespace = "http://locahost/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
[System.Web.Script.Services.ScriptService]
public class WellnessService : System.Web.Services.WebService
{
[WebMethod]
public string MethodName()
{
return ViewManager.RenderView("~/Modules/CouponsPromotions/CouponCenter.ascx");
}
}
public class ViewManager
{
public static string RenderView(string path)
{
return RenderView(path, null);
}
public static string RenderView(string path, object data)
{
Page pageHolder = new Page();
UserControl viewControl = (UserControl)pageHolder.LoadControl(path);
if (data != null)
{
Type viewControlType = viewControl.GetType();
FieldInfo field = viewControlType.GetField("Data");
if (field != null)
{
field.SetValue(viewControl, data);
}
else
{
throw new Exception("View file: " + path + " does not have a public Data property");
}
}
pageHolder.Controls.Add(viewControl);
StringWriter output = new StringWriter();
HttpContext.Current.Server.Execute(pageHolder, output, false);
return output.ToString();
}
}
これは私がJS
$(document).ready(function() {
$('#liCoupons').click(function() {
$.ajax({
type: "POST",
url: "/services.asmx/MethodName",
data: "",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
$('#result').html(msg.d);
},
error: ajaxFailed
//error
});
});
function ajaxFailed(xmlRequest) {
alert(xmlRequest.status + ' \n\r ' +
xmlRequest.statusText + '\n\r' +
xmlRequest.responseText);
}
});
URL書き換えをどこに使用していますか?それは私の世界を何百万回も吹き飛ばした。 :) – coderpros
あなたはどのようにWebサービスを消費していますか? JS経由でコードを投稿してください –
@coderpros私はこのURL http://localhost/service.asmx/MethodNameをWebブラウザで指しても、基本的に@PankajKumarのURLを書き換えません。 – xoail