小编Ste*_*eve的帖子

从web.config按名称读取WCF服务端点地址

在这里,我试图从web.config中按名称读取我的服务端点地址

ClientSection clientSection = (ClientSection)ConfigurationManager.GetSection("system.serviceModel/client");
var el = clientSection.Endpoints("SecService"); // I don't want to use index here as more endpoints may get added and its order may change
string addr = el.Address.ToString();
Run Code Online (Sandbox Code Playgroud)

有没有办法可以根据名称读取终点地址?

这是我的web.config档案

<system.serviceModel>
 <client>
     <endpoint address="https://....................../FirstService.svc" binding="wsHttpBinding" bindingConfiguration="1ServiceBinding" contract="abc.firstContractName" behaviorConfiguration="FirstServiceBehavior" name="FirstService" />
     <endpoint address="https://....................../SecService.svc" binding="wsHttpBinding" bindingConfiguration="2ServiceBinding" contract="abc.secContractName" behaviorConfiguration="SecServiceBehavior" name="SecService" />
     <endpoint address="https://....................../ThirdService.svc" binding="wsHttpBinding" bindingConfiguration="3ServiceBinding" contract="abc.3rdContractName" behaviorConfiguration="ThirdServiceBehavior" name="ThirdService" />
            </client>
    </system.serviceModel>
Run Code Online (Sandbox Code Playgroud)

这将工作clientSection.Endpoints[0];,但我正在寻找一种方法来检索名称.

就像这样clientSection.Endpoints["SecService"],但它不起作用.

c# wcf web-config

18
推荐指数
3
解决办法
3万
查看次数

从azure blob存储文件生成Zip文件

我有一些文件存储在我的windows azure blob存储中.我想获取这些文件并创建一个zip文件并存储到一个新文件夹.然后返回zip文件的路径.设置zip文件位置的权限,以便我的用户可以通过单击链接将zip文件下载到本地计算机

 https://mystorage.blob.core.windows.net/myfiles/2b5f8ea6-3dc2-4b77-abfe-4da832e02556/AppList/isjirleq/mydocs1.doc
 https://mystorage.blob.core.windows.net/myfiles/2b5f8ea6-3dc2-4b77-abfe-4da832e02556/tempo/xyz/mymusic.mp3
 https://mystorage.blob.core.windows.net/myfiles/2b5f8ea6-3dc2-4b77-abfe-4da832e02556/general/video/myVideo.wmv
 https://mystorage.blob.core.windows.net/myfiles/2b5f8ea6-3dc2-4b77-abfe-4da832e02556/photo/photo1.png
Run Code Online (Sandbox Code Playgroud)

我希望能够循环这些文件并将它们一起压缩以创建一个新的zip文件

(https://mystorage.blob.core.windows.net/myzippedfiles/allmyFiles.zip)并返回zip文件的路径

我的azure blob中有大量文件.所以下载它们并压缩它们并上传并不是一个好主意.

我该怎么做.我需要一些示例代码来执行此操作

c# azure azure-storage-blobs visual-studio-2012

18
推荐指数
2
解决办法
2万
查看次数

WCF错误未提供客户端证书.在ClientCredentials中指定客户端证书

我正在尝试调用WCF服务.我创建了一个自签名证书并安装在我的localmachine\personnal\certificates中,我也在我的部分中添加了.但我不明白为什么会出现此错误.

这是我的web.config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.serviceModel>
        <bindings>
            <wsHttpBinding>
                <binding name="wsHttpEndpoint">
                    <security mode="Transport">
                        <transport clientCredentialType="Certificate" />
                    </security>
                </binding>
            </wsHttpBinding>
        </bindings>
        <client>
            <endpoint address="https://abcdxyz.abc.syntax.com/TestCCService.svc"
                binding="wsHttpBinding" bindingConfiguration="wsHttpEndpoint"
                contract="TestCCService.ITestCCService" name="wsHttpEndpoint" />
        </client>

        <behaviors>
            <endpointBehaviors>
                <behavior name="CustomBehavior">
                    <clientCredentials>
                        <clientCertificate findValue="abc.mymachine.name.com" x509FindType="FindBySubjectName"
                          storeLocation="LocalMachine" storeName="My" />
                        </clientCredentials>
                </behavior>
            </endpointBehaviors>
        </behaviors>

    </system.serviceModel>
</configuration>
Run Code Online (Sandbox Code Playgroud)

但是当我尝试调用我的服务方法时抛出错误"未提供客户端证书.在ClientCredentials中指定客户端证书."

感谢您的建议以解决此错误?

wcf wshttpbinding

10
推荐指数
1
解决办法
2万
查看次数

如何创建一个模拟HttpWebRequest和HttpWebResponse对象

如何创建模拟HttpWebRequest和HttpWebResponse对象我试图对下面这段代码进行单元测试

HttpWebrequest request;   

if (null != request)
{                         
    var response = (HttpWebResponse)request.GetResponse();
    using (var sr = new StreamReader(response.GetResponseStream()))
    {
        jsonResult = sr.ReadToEnd();
    }

    var myRecords = SerializationHelper.Deserialize<Records>(jsonResult);
}
Run Code Online (Sandbox Code Playgroud)

c# unit-testing

10
推荐指数
1
解决办法
7048
查看次数

找不到方法'Void Newtonsoft.Json.Serialization.DefaultContractResolver.set_IgnoreSerializableAttribute(Boolean)

我下载了一个webapi的示例代码,我得到了这个例外我使用Visual Studio 2012 Ultimate Version打开了这个示例,我安装了最新版本的newtonsoft.我运行这个应用程序时遇到这个错误.它编译成功.知道为什么会出现这个错误并且有办法解决这个异常.

System.MissingMethodException was unhandled by user code
  HResult=-2146233069
  Message=Method not found: 'Void Newtonsoft.Json.Serialization.DefaultContractResolver.set_IgnoreSerializableAttribute(Boolean)'.
  Source=System.Net.Http.Formatting
  StackTrace:
       at System.Net.Http.Formatting.JsonContractResolver..ctor(MediaTypeFormatter formatter)
       at System.Net.Http.Formatting.JsonMediaTypeFormatter..ctor()
       at System.Net.Http.Formatting.MediaTypeFormatterCollection.CreateDefaultFormatters()
       at System.Net.Http.Formatting.MediaTypeFormatterCollection..ctor()
       at System.Web.Http.HttpConfiguration.DefaultFormatters()
       at System.Web.Http.HttpConfiguration..ctor(HttpRouteCollection routes)
       at System.Web.Http.GlobalConfiguration.<.cctor>b__0()
       at System.Lazy`1.CreateValue()
       at System.Lazy`1.LazyInitValue()
       at System.Lazy`1.get_Value()
       at System.Web.Http.GlobalConfiguration.get_Configuration()
       at System.Web.Http.RouteCollectionExtensions.MapHttpRoute(RouteCollection routes, String name, String routeTemplate, Object defaults, Object constraints, HttpMessageHandler handler)
       at System.Web.Http.RouteCollectionExtensions.MapHttpRoute(RouteCollection routes, String name, String routeTemplate, Object defaults)
       at WebAPIRc.RouteConfig.RegisterRoutes(RouteCollection routes) in c:\Users\viemon\Downloads\WebAPIRc\WebAPIRc\WebAPIRc\App_Start\RouteConfig.cs:line 17
       at WebAPIRc.WebApiApplication.Application_Start() in c:\Users\viemon\Downloads\WebAPIRc\WebAPIRc\WebAPIRc\Global.asax.cs:line 36
  InnerException: 
Run Code Online (Sandbox Code Playgroud)

这是失败的代码

public class …
Run Code Online (Sandbox Code Playgroud)

c# json.net visual-studio-2012

7
推荐指数
1
解决办法
2万
查看次数

错误反序列化类型的对象....结束元素'......'从命名空间''预期.从命名空间''找到元素'item'

当我反序列化我的jsonstring时,我收到错误消息

 There was an error deserializing the object of type RecordInfo. End element 'Warning' from namespace '' expected. Found element 'item' from namespace ''.
Run Code Online (Sandbox Code Playgroud)

这是我的JsonString

public const string jsonString = @" 
        {
            ""RequestId"":514106,
            ""Warning"":[],
            ""CustomerData"": {
                ""Email"":""abc@abc.com"",
                ""FullName"":""OrTguOfE"",
                ""OrderData"":[]
            }
        }";
Run Code Online (Sandbox Code Playgroud)

数据合同

[DataContract]
    public class RecordInfo
    {
        [DataMember(Name = "RequestId")]
        public string RequestId { get; set; }

        [DataMember(Name = "Warning")]
        public string Warning { get; set; }

        [DataMember(Name = "CustomerData")]
        public CustomerData CustomerData { get; set; }
    }
 [DataContract]
    public …
Run Code Online (Sandbox Code Playgroud)

c# json datacontractjsonserializer

5
推荐指数
1
解决办法
2万
查看次数

自创建数据库以来,支持'myDBContext'上下文的模型已更改.考虑使用Code First Migrations来更新数据库

我对Entity进行了一些更改,并在packageManager控制台中成功执行了"update-database -verbose",我可以看到azure数据库中反映的更改.

然后我对azure云进行了部署,我从Azure云获取了错误消息

"The model backing the 'myDBContext' context has changed since the database was created. Consider using Code First Migrations to update the database"
Run Code Online (Sandbox Code Playgroud)

我尝试设置Configuration.AutoDetectChangesEnabled = false并重新部署

但我仍然得到同样的错误.

请帮忙 ..

entity-framework azure azure-sql-database

2
推荐指数
1
解决办法
3454
查看次数