我的印象是,在配置文件中将端点定义为可能的客户端列表,但这没有任何意义(从某种意义上说,我认为它说的是什么计算机可以连接到服务)现在我正在收集它更多一个定义,那么有人请解释一下我的终点是什么吗?我理解定义合同接口然后实现合同的概念,但我迷失在那里,实际上有一些可用的东西.
在这种情况下,地址是什么?主持人地址?
绑定是使用正确的通信方法/协议吗?
合同本质上是"共享的对象"(是的,我知道这在技术上是不正确的,但在这里与我合作)
如何确定连接套接字的远程IP地址?
我有一个我可以访问的RemoteEndPoint对象以及它的AddressFamily成员.
如何利用这些来查找IP地址?
谢谢!
目前正在尝试
IPAddress.Parse( testSocket.Address.Address.ToString() ).ToString();
Run Code Online (Sandbox Code Playgroud)
并获得1.0.0.127而不是127.0.0.1的localhost端点.这是正常的吗?
我试图从.NET客户端应用程序中使用WCF Web服务,我认为我需要能够以编程方式创建端点,但我不知道如何.我想我需要这样做,因为当我尝试运行应用程序时,我收到以下错误:
无法在ServiceModel客户端配置部分中找到引用合同"IEmailService"的默认端点元素.这可能是因为没有为您的应用程序找到配置文件,或者因为在客户端元素中找不到与此合同匹配的端点元素.
在解决此错误时,我创建了一个简单的Windows窗体应用程序,我尝试使用相同的Web服务.使用此测试应用程序,我可以成功连接到Web服务,并获得有效的响应.但是,我可以在我的测试应用程序中通过从应用程序的app.config文件中删除system.serviceModel节点及其所有子节点来重现上面引用的确切错误(我可能不必删除所有该部分,我是不确定).所以,我的第一个想法是我需要将该部分添加到真实应用程序的app.config文件中,一切都应该没问题.不幸的是,由于荒谬的原因,我不会进入这里,这不是一个选择.所以,我不得不在客户端应用程序内的代码中生成此信息.
我希望有人可以帮助我解决这个问题,或者可以指出我为这类问题寻找一个好的资源.
是否可以在代码中在客户端应用程序中创建端点配置?
如何编写ac#sample以读取我的客户端端点配置:
<client>
<endpoint address="http://mycoolserver/FinancialService.svc"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IFinancialService"
contract="IFinancialService" name="WSHttpBinding_IFinancialService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="http://mycoolserver/HumanResourcesService.svc"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IHumanResourceService"
contract="IHumanResourceService" name="WSHttpBinding_IHumanResourceService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
Run Code Online (Sandbox Code Playgroud)
目标是获取一组端点地址:
List<string> addresses = GetMyCurrentEndpoints();
Run Code Online (Sandbox Code Playgroud)
结果我们会:
[0] http://mycoolserver/FinancialService.svc
[1] http://mycoolserver/HumanResourcesService.svc
Run Code Online (Sandbox Code Playgroud) 我有一个包含几个WCF服务的程序集,每个服务都有自己的合同.这一切都很好.app.config中服务的服务配置如下所示:
<services>
<service behaviorConfiguration="WcfService.AlyzaServiceBehavior"
name="Sam.Alyza.WcfService.ServiceWebsites">
<endpoint address="" binding="netTcpBinding" contract="Sam.Alyza.WcfInterface.IServiceWebsites">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:8731/Design_Time_Addresses/SamAlyza/Websites/" />
</baseAddresses>
</host>
</service>
<service behaviorConfiguration="Sam.Alyza.WcfService.LogReaderServiceBehavior"
name="Sam.Alyza.WcfService.ServiceLogReader">
<endpoint address="" binding="netTcpBinding" contract="Sam.Alyza.WcfInterface.IServiceLogReader">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:8731/Design_Time_Addresses/SamAlyza/LogReader/" />
</baseAddresses>
</host>
</service>
<service behaviorConfiguration="Sam.Alyza.WcfService.ServiceSystemverwaltungBehavior"
name="Sam.Alyza.WcfService.ServiceSystemverwaltung">
<endpoint address="" binding="netTcpBinding" contract="Sam.Alyza.WcfInterface.IServiceSystemverwaltung">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:8731/Design_Time_Addresses/SamAlyza/Systemverwaltung/" />
</baseAddresses>
</host>
</service> …
Run Code Online (Sandbox Code Playgroud) 我部署了一个JAX-WS服务并使用wsimport生成客户端代码.因为我在localhost上运行wsimport,所以我在"localhost"地址上使用binind获取了客户端代码.
但我想在其他使用公共IP yyyy访问我部署的服务的计算机上重用这些客户端代码.如何动态使用这些(一次)生成的客户端代码来访问我的服务.(服务的IP可能会改变......)
我想要做的是让一个单一的WCF服务在HTTP方案的开发环境中工作,并且在生产环境中使用SAME服务也是HTTPS方案.如果我删除两个Https端点(后缀为'Https'),它可以在开发环境中工作; 同样,如果我只删除两个Http端点,那么它在生产环境中工作.如果可能的话,我想在web.config中拥有所有四个端点.
我的终点定义如下:
<endpoint address="/Web"
behaviorConfiguration="AjaxBehavior"
binding="wsHttpBinding"
bindingConfiguration="web"
name="Web"
contract="Service" />
<endpoint address="/Custom"
binding="customBinding"
bindingConfiguration="custom"
name="Custom"
contract="Service" />
<endpoint
address="/WebHttps"
behaviorConfiguration="AjaxBehavior"
binding="wsHttpBinding"
bindingConfiguration="webHttps"
name="WebHttps"
contract="Service" />
<endpoint address="/CustomHttps"
binding="customBinding"
bindingConfiguration="customHttps"
name="CustomHttps"
contract="Service" />
Run Code Online (Sandbox Code Playgroud)
编辑:我正在编辑我的问题,以添加我得到的错误,以及绑定部分(下面).对不起这个问题的新篇幅.
错误是:"无法找到与绑定WebHttpBinding的端点的方案http匹配的基址.已注册的基址方案为[https]."
此外,生产站点设置为"需要SSL".那无法改变.
绑定配置是:
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="AjaxBehavior">
<enableWebScript/>
</behavior>
</endpointBehaviors>
</behaviors>
<bindings>
<customBinding>
<binding name="custom">
<textMessageEncoding>
<readerQuotas maxDepth="7000000" maxStringContentLength="7000000"
maxArrayLength="7000000" maxBytesPerRead="7000000"
maxNameTableCharCount="7000000" />
</textMessageEncoding>
<httpTransport maxBufferPoolSize="7000000" maxReceivedMessageSize="7000000"
maxBufferSize="7000000" />
</binding>
<binding name="customHttps">
<textMessageEncoding> …
Run Code Online (Sandbox Code Playgroud) 我目前正在使用SendGrid的Inbound Parse Webhook将电子邮件提供给我的应用程序.我已经能够通过将URL指向我的应用程序已公开的端点来使其工作.SendGrid只是以JSON格式HTTP POST请求的形式将电子邮件发送到此端点,我只是在内部处理每个请求.
我的问题是,现在我有它工作,我如何确保只有SendGrid才能使用这个端点?目前,任何人都可以使用此HTTP POST端点并假装已将电子邮件发送到应用程序.
我可以让SendGrid发送某种独特的密钥来识别自己吗?有没有办法可以通过IP地址限制?
我最初几次尝试创建自托管服务.尝试创建一些接受查询字符串并返回一些文本但有一些问题的东西:
所有文档都讨论了如果在配置文件中找不到端点,则会自动为每个基址创建端点.这对我来说似乎不是这样,我得到"服务没有应用程序端点......"的例外情况.手动指定基本端点如下所示似乎解决了这个问题:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using System.ServiceModel.Description;
namespace TestService
{
[ServiceContract]
public interface IHelloWorldService
{
[OperationContract]
string SayHello(string name);
}
public class HelloWorldService : IHelloWorldService
{
public string SayHello(string name)
{
return string.Format("Hello, {0}", name);
}
}
class Program
{
static void Main(string[] args)
{
string baseaddr = "http://localhost:8080/HelloWorldService/";
Uri baseAddress = new Uri(baseaddr);
// Create the ServiceHost.
using (ServiceHost host = new ServiceHost(typeof(HelloWorldService), baseAddress))
{
// Enable metadata publishing.
ServiceMetadataBehavior smb = …
Run Code Online (Sandbox Code Playgroud)似乎boost :: asio为每个协议定义了一个单独的端点类,如果你想在特定端点上执行UDP和TCP操作(必须从一个转换为另一个),这会很烦人.我总是只想到一个端点作为IP地址(v4或v6)和端口号,无论TCP或UDP如何.是否存在显着差异以证明单独的类别?(即,tcp :: socket和udp :: socket都不能接受类似ip :: endpoint的东西?)
endpoints ×10
wcf ×6
c# ×3
web-services ×2
.net ×1
app-config ×1
base-address ×1
boost-asio ×1
dynamic ×1
jax-ws ×1
self-hosting ×1
sendgrid ×1
sockets ×1
webhooks ×1
wsdl ×1
wsimport ×1