如何获取WCF RIA服务URL

时间:2014-01-06 09:08:57

标签: asp.net silverlight wcf-ria-services

我创建了一个基于ASP.Net网站的WFC RIA服务,并为RIA服务添加了nuget包。我还通过扩展DomainService类创建了名为“FactoryService”的服务。

我通过创建一个指向该服务的DomainDataSource的GridView来测试该服务。该服务正在运作。

现在我想从其他客户端访问该服务,因为我启用了SOAP端点。但是我找不到svc文件的服务URL。我需要这个url来为我的其他项目添加服务引用。我如何找到服务网址?

我尝试了以下网址,并且全部返回404.(名称空间“WebApplication3”,DomainService类“FactoryService”)。

 - http://localhost:15066/WebApplication3-FactoryService.svc
 - http://localhost:15066/services/WebApplication3-FactoryService.svc
 - http://localhost:15066/ClientBin/WebApplication3-FactoryService.svc
 - http://localhost:15066/FactoryService.svc
 - http://localhost:15066/services/FactoryService.svc
 - http://localhost:15066/ClientBin/FactoryService.svc

2 个答案:

答案 0 :(得分:1)

我发现了这个问题。在DomainService类中,我错过了使用[EnableClientAccess()]注释它。

  

域服务类必须标记为   EnableClientAccessAttribute属性使服务可用   客户项目。 EnableClientAccessAttribute属性是   选择“启用”时自动应用于域服务   “添加新域服务类”对话框中的“客户端访问”复选框   框。

当我使用VS2013时,向导不可用,并且错过了使用属性注释它。

答案 1 :(得分:0)

通常它有以下形式

DomainService的Base-Address + ClientBin + FullName(名称空间+ TypeName由-分隔) 所以在你的情况下它应该看起来像

http://localhost:15066/ClientBin/WebApplication3-FactoryService.svc

当您在浏览器中访问此链接时,您将看到一个类似于此

的页面
Service

You have created a service.

To test this service, you will need to create a client and use it to call the service. You can do this using the svcutil.exe tool from the command line with the following syntax:


svcutil.exe http://localhost:15066/ClientBin/WebApplication3-FactoryService.svc?wsdl
You can also access the service description as a single file:

http://localhost:15066/ClientBin/WebApplication3-FactoryService.svc?singleWsdl
This will generate a configuration file and a code file that contains the client class. Add the two files to your client application and use the generated client class to call the Service. For example:

C#

class Test
{
    static void Main()
    {
        HelloClient client = new HelloClient();

        // Use the 'client' variable to call operations on the service.

        // Always close the client.
        client.Close();
    }
}

Visual Basic

Class Test
    Shared Sub Main()
        Dim client As HelloClient = New HelloClient()
        ' Use the 'client' variable to call operations on the service.

        ' Always close the client.
        client.Close()
    End Sub
End Class