2015-10-02 28 views
0

我在IIS上托管一个WCF服务(一个服务函数库)。vb.net WCF服务库函数没有公开 - 它只能看到IIS主机的默认服务(2个函数)

我应该看到(公开)我的服务库中创建的NotificationsService的函数 - NotificationAdd - 但我不知道。有人知道为什么

我使用VS 2013创建了3个项目VB.net解决方案。 1个项目为WCF服务库 1个项目为IIS主机。 1个UI项目。

WCF服务库的项目。 1个功能服务。被称为NotificationsServiceLibrary。

的INotificationsService.vb

Imports System 
Imports System.ServiceModel 
Imports System.ServiceModel.Web 

Namespace NotificationsServiceLibrary 

    <ServiceContract()> 
    Public Interface INotificationsService 

     <OperationContract> 
     Function NotificationAdd(ByVal pStrUserName As String, ByVal pStrPassword As String, ByVal pStrEmailAddress As String, ByVal pStrSummary As String, ByVal pStrDetail As String, ByVal pStrSource As String, ByVal pStrSourceURL As String, ByVal pDtWhenGenerated As Date, ByVal pDdtSchedule As Date) As NotificationsInfoResult 

    End Interface 
End Namespace 

的NotificationsService.vb

Imports System 
Imports System.IO 
Imports System.ServiceModel 
Imports System.Configuration 
Imports System.Xml 
Imports System.Data.SqlClient 

Namespace NotificationsServiceLibrary 

    <ServiceBehavior(InstanceContextMode:=InstanceContextMode.Single)> 
    Public Class NotificationsService 
     Implements INotificationsService 

     Public Function NotificationAdd(ByVal pStrUserName As String, ByVal pStrPassword As String, ByVal pStrEmailAddress As String, ByVal pStrSummary As String, ByVal pStrDetail As String, ByVal pStrSource As String, ByVal pStrSourceURL As String, ByVal pDtWhenGenerated As Date, ByVal pDdtSchedule As Date) As NotificationsInfoResult Implements INotificationsService.NotificationAdd 

      ' Code here..but removed to keep this short. 

      ' Return. 
      Return notificationsInfoResult 
     End Function 
    End Class 
End Namespace 

的NotificationsServiceData.vb

Imports System 
Imports System.Collections.Generic 
Imports System.Linq 
Imports System.Text 
Imports System.Threading.Tasks 
Imports System.Runtime.Serialization 

<DataContract()> 
Public Class NotificationsInfoResult 
    Private _result_code As Integer 

    <DataMember()> 
    Public Property Result_Code() As Integer 
     Get 
      Return _result_code 
     End Get 

     Set(value As Integer) 
      _result_code = value 
     End Set 
    End Property 
End Class 

以下是IIS主机项目,我发布到IIS。称为:NotificationsApiIISHost。 在IIS主机项目中,我添加了对NotificationsServiceLibrary的项目引用。 如果我点击它,我可以在对象浏览器中看到我应该暴露的1个函数。

的IIS主机项目2个标准的默认文件(我不使用也不修改),并且我加入到Web.config:

IService1.vb

<ServiceContract()> 
Public Interface IService1 

    <OperationContract()> 
    Function GetData(ByVal value As Integer) As String 

    <OperationContract()> 
    Function GetDataUsingDataContract(ByVal composite As CompositeType) As CompositeType 

    ' TODO: Add your service operations here 

End Interface 

' Use a data contract as illustrated in the sample below to add composite 
types to service operations. 

<DataContract()> 
Public Class CompositeType 

    <DataMember()> 
    Public Property BoolValue() As Boolean 

    <DataMember()> 
    Public Property StringValue() As String 
End Class 

Service1.svc

Public Class Service1 
    Implements IService1 

    Public Sub New() 
    End Sub 

    Public Function GetData(ByVal value As Integer) As String Implements IService1.GetData 
     Return String.Format("You entered: {0}", value) 
    End Function 

    Public Function GetDataUsingDataContract(ByVal composite As CompositeType) As CompositeType Implements IService1.GetDataUsingDataContract 
     If composite Is Nothing Then 
      Throw New ArgumentNullException("composite") 
     End If 
     If composite.BoolValue Then 
      composite.StringValue &= "Suffix" 
     End If 
     Return composite 
    End Function 
End Class 

的IIS主机的web.config:

<?xml version="1.0"?> 
<configuration> 
    <system.web> 
    <compilation debug="true" strict="false" explicit="true" targetFramework="4.5" /> 
    <httpRuntime targetFramework="4.5"/> 
    <customErrors mode="Off"/> 
    </system.web> 
    <system.serviceModel> 
    <services> 
     <service name="NotificationsServiceLibrary.NotificationsServiceLibrary.NotificationsService"> 
     <!-- Service Endpoints --> 
     <endpoint address="Notifications" binding="wsHttpBinding" contract="NotificationsServiceLibrary.NotificationsServiceLibrary.INotificationsService"  bindingConfiguration="NoSecurityConfig" > 
     </endpoint> 
     <!-- Metadata Endpoints --> 
     <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/> 
     </service> 
    </services> 
    <bindings> 
     <wsHttpBinding> 
     <binding name="NoSecurityConfig"> 
      <security mode="None"> 
      <transport clientCredentialType="None" /> 
      <message establishSecurityContext="false" /> 
      </security> 
      <reliableSession enabled="true" /> 
     </binding> 
     </wsHttpBinding> 
    </bindings> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior> 
      <serviceMetadata httpGetEnabled="True" httpsGetEnabled="True"/> 
      <serviceDebug includeExceptionDetailInFaults="True" /> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" /> 
    </system.serviceModel> 
    <system.webServer> 
    <modules runAllManagedModulesForAllRequests="true"/> 
    <directoryBrowse enabled="true"/> 
</system.webServer> 
</configuration> 

构建并发布主机之后。

以下是在IIS上自动创建的Service1.svc文件的内容。

<%@ ServiceHost Language="VB" Debug="true" 
Service="NotificationsApiIISHost.Service1" CodeBehind="Service1.svc.vb" %> 

我得到VS: ------发布开始:项目:NotificationsApiIISHost,配置:调试任何CPU ------ 连接到ftp://dev.notifications.xxxx.net:2121 ... 转化利用的Web.config C:\ Dans \ Work 2 \ xxxx \ NotificationsApiIISHost \ Web.Debug.config转换为obj \ Debug \ TransformWebConfig \ transformed \ Web.config。 将所有文件复制到以下临时位置以进行打包/发布: obj \ Debug \ Package \ PackageTmp。 删除现有文件... 发布文件夹/ ... 发布文件夹bin ... 网站已成功发布ftp://dev.notifications.xxxx.net:2121/ 网站已成功发布http://dev.notifications.xxx.net/ ==========构建:0成功,0失败,2最新,0跳过========== ==========发布:1次成功,0次失败,0次跳过==========

我在显示的页面上单击Service1.svc:

dev.notifications.xxxxxx.net -/

2015年10月1日下午10时49分仓

10 /二千○十五分之一下午10时49分120 Service1.svc

2015年10月1日下午10时49分2900的Web.config

然后我点击http://xxxxx/Service1.svc?singleWsdl和 所有我看到的是默认的主机服务功能 - GetData和GetDataUsingDataContract。 当我创建IIS主机时,这些放置在那里。甚至没有用过我。 我应该看到我在我的服务库中创建的功能,但我不知道。

这里的WSDL的部分:

<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:wsx="http://schemas.xmlsoap.org/ws/2004/09/mex" xmlns:wsap="http://schemas.xmlsoap.org/ws/2004/08/addressing/policy" xmlns:msc="http://schemas.microsoft.com/ws/2005/12/wsdl/contract" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="http://tempuri.org/" xmlns:wsa10="http://www.w3.org/2005/08/addressing" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" name="Service1" targetNamespace="http://tempuri.org/"> 
<wsdl:types> 
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="http://tempuri.org/"> 
<xs:import namespace="http://schemas.datacontract.org/2004/07/NotificationsApiIISHost"/> 
<xs:element name="GetData"> 
<xs:complexType> 
<xs:sequence> 
<xs:element minOccurs="0" name="value" type="xs:int"/> 
</xs:sequence> 
</xs:complexType> 
</xs:element> 
<xs:element name="GetDataResponse"> 
<xs:complexType> 
<xs:sequence> 
<xs:element minOccurs="0" name="GetDataResult" nillable="true" type="xs:string"/> 
</xs:sequence> 
</xs:complexType> 
</xs:element> 
<xs:element name="GetDataUsingDataContract"> 
<xs:complexType> 
<xs:sequence> 
<xs:element xmlns:q1="http://schemas.datacontract.org/2004/07/NotificationsApiIISHost" minOccurs="0" name="composite" nillable="true" type="q1:CompositeType"/> 
</xs:sequence> 
</xs:complexType> 
</xs:element> 
<xs:element name="GetDataUsingDataContractResponse"> 
<xs:complexType> 
<xs:sequence> 
<xs:element xmlns:q2="http://schemas.datacontract.org/2004/07/NotificationsApiIISHost" minOccurs="0" name="GetDataUsingDataContractResult" nillable="true" type="q2:CompositeType"/> 
</xs:sequence> 
</xs:complexType> 
</xs:element> 
</xs:schema> 
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://schemas.microsoft.com/2003/10/Serialization/" attributeFormDefault="qualified" elementFormDefault="qualified" 
+0

我没有明白你想要什么......你想公开NotificationsService方法NotificationAdd? –

+0

@Ricardo。对,就是这样。 – user3020047

回答

0

有两件事情会在这里的。首先,你已经创建了一个WCF服务库。其次,看起来您尝试将服务库托管在WCF服务应用程序中。

首先,删除样板服务文件。你不需要它们,它只会混淆事物。

其次,添加一个新文件(我通常添加一个文本文件并更改扩展名),命名为“NotificationService.svc”。

打开该文件在IDE中,并添加以下的标记:

<%@ ServiceHost Language="VB" Debug="true" Service="NotificationsServiceLibrary.NotificationsService" %> 
<%@ Assembly Name="<whatever your service library assembly name is>" %> 

当IIS接收到的服务页面的请求时,它会使用ServiceHostFactory来创建服务,该服务包含的一个实例在引用的程序集中。

+0

@Tim ...非常感谢。那样做了。 – user3020047

+0

@ user3020047 - 不客气。快乐的编码! – Tim