我有一项服务(EmailSender
)。这是配置文件:
<?xml version="1.0"?>
<configuration>
<connectionStrings>
<add name="Conn" connectionString="Data Source=localhost;Initial Catalog=DT.DBTest;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<bindings>
<webHttpBinding>
<binding name="webHttpBindingWithJsonP" crossDomainScriptAccessEnabled="true" />
</webHttpBinding>
</bindings>
<services>
<service name="DT.myapp.Services.PremieraInteraction">
<endpoint address="" binding="webHttpBinding"
bindingConfiguration="webHttpBindingWithJsonP"
contract="DT.myapp.Services.IPremieraInteraction"
behaviorConfiguration="webHttpBehavior"/>
</service>
<service name="DT.myapp.Services.EmailSender">
<endpoint address="" binding="webHttpBinding"
contract="DT.myapp.Services.IEmailSender"
behaviorConfiguration="webHttpBehavior"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="webHttpBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
在另一个(asp.net mvc)应用程序中,我想调用此服务。这是代理类:
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")]
[System.ServiceModel.ServiceContractAttribute(ConfigurationName = "IEmailSender")]
public interface IEmailSender
{
[System.ServiceModel.OperationContractAttribute(Action = "http://tempuri.org/IEmailSender/SendRegistrationEmail", ReplyAction = "http://tempuri.org/IEmailSender/SendRegistrationEmailResponse")]
void SendRegistrationEmail();
[System.ServiceModel.OperationContractAttribute(Action = "http://tempuri.org/IEmailSender/SendETicket", ReplyAction = "http://tempuri.org/IEmailSender/SendETicketResponse")]
void SendETicket();
[System.ServiceModel.OperationContractAttribute(Action = "http://tempuri.org/IEmailSender/SendTestEmail", ReplyAction = "http://tempuri.org/IEmailSender/SendTestEmailResponse")]
void SendTestEmail();
}
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")]
public interface IEmailSenderChannel : IEmailSender, System.ServiceModel.IClientChannel
{
}
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")]
public partial class EmailSenderClient : System.ServiceModel.ClientBase<IEmailSender>, IEmailSender
{
public EmailSenderClient()
{
}
public EmailSenderClient(string endpointConfigurationName) :
base(endpointConfigurationName)
{
}
public EmailSenderClient(string endpointConfigurationName, string remoteAddress) :
base(endpointConfigurationName, remoteAddress)
{
}
public EmailSenderClient(string endpointConfigurationName, System.ServiceModel.EndpointAddress remoteAddress) :
base(endpointConfigurationName, remoteAddress)
{
}
public EmailSenderClient(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) :
base(binding, remoteAddress)
{
}
public void SendRegistrationEmail()
{
base.Channel.SendRegistrationEmail();
}
public void SendETicket()
{
base.Channel.SendETicket();
}
public void SendTestEmail()
{
base.Channel.SendTestEmail();
}
}
而且,我如何打电话:
Binding binding = new BasicHttpBinding(BasicHttpSecurityMode.None);
EndpointAddress endpointAddress = new EndpointAddress(new Uri("http://localhost:12736/EmailSender.svc"));
EmailSenderClient client = new EmailSenderClient(binding, endpointAddress);
client.SendTestEmail();
但是,我收到了错误:
There was no endpoint listening at http://localhost:12736/EmailSender.svc that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.
InnerException
说:
The remote server returned an error: (404) Not Found.
哪里出错?
感谢。