开发者

Trouble adding web service/service reference on the aspx page

开发者 https://www.devze.com 2023-04-05 19:41 出处:网络
I think I got the web.config right but I\'d want to know how to add the service reference or the web service itself on the aspx page so my script could access it.

I think I got the web.config right but I'd want to know how to add the service reference or the web service itself on the aspx page so my script could access it.

here's what I did but it doesn't work:

<%@ ServiceHost Language=C# Service="WebService" CodeBehind="http://urlToMyService.svc"%>

<asp:ScriptManager ID="ScriptManager1" runat="server">
   <Services&g开发者_开发技巧t;
      <asp:ServiceReference 
         Path="http://urlToMyService.svc"/>
   </Services>
</asp:ScriptManager>

I think I need to add the <%@ ServiceHost %> and <asp:ScriptManager> but I'd like a clearer example on every parameters I need to include.


You can add only references to local services (i.e. services that exist in your ASP.NET web application). So typical service reference goes like

<asp:ScriptManager ID="ScriptManager1" runat="server">
    <Services>
        <asp:ServiceReference Path="~/HelloWorldService.svc" />
    </Services>
</asp:ScriptManager>

on aspx page (or master page or user control). You don't need <%@ ServiceHost %> etc - that will appear in svc file.

Note that adding service reference to ScriptManager generates a java script service proxy that will simplify calling your web service from java-script. This is not useful for calling the service from code (on server side). See this tutorial to get started on invoking services from java-script: http://www.codeproject.com/KB/aspnet/wcfinjavascript.aspx

For calling services from server side code, you have to add service reference from Visual Studio (right-click on your project and choose Add Service Reference context menu) - in such case, VS generates the proxy code to make call to the service.

0

精彩评论

暂无评论...
验证码 换一张
取 消