首页 > 其他分享 >WCF调https时调用失败的问题

WCF调https时调用失败的问题

时间:2022-11-30 14:55:05浏览次数:48  
标签:info files 调用 System upload https WCF new

最近做项目的时候,发现wcf调http可以正常,https就调用失败,但是那项目布在http,就可以正常调,布在https,就调失败了。

红框位置为建立安全通道,不管是http还是https都可以正常调用到了,UrlAddress为我自己写在配置文件的配置地址

代码

 1  /// <summary>
 2         /// 图片上传
 3         /// </summary>
 4         /// <param name="request">请求SassApi实体</param>
 5         /// <returns></returns>
 6         public static ApiResponseEntity UploadImg(UploadFileInfoRequest request, IFormFile files)
 7         {
 8             var address = SettingConfigUtil.GetAppJsonValue<String>("UrlAddress", String.Empty).TrimEnd('/') + "/Common_UploadFileWCFService.svc";
 9             // todo 通过接口上传到服务器端,保存成文件
10             System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12; //建立SSL/TLS 安全通道
11             System.ServiceModel.BasicHttpSecurityMode securityMode = System.ServiceModel.BasicHttpSecurityMode.None;
12             if (address.StartsWith("https", true, null))
13             {
14                 securityMode = System.ServiceModel.BasicHttpSecurityMode.Transport;
15             }
16             upload.Common_UploadFileWCFServiceClient client = new upload.Common_UploadFileWCFServiceClient(new System.ServiceModel.BasicHttpBinding(securityMode)
17             {
18                 OpenTimeout = new TimeSpan(0, 1, 0),
19                 CloseTimeout = new TimeSpan(0, 1, 0),
20                 SendTimeout = new TimeSpan(0, 10, 00),
21                 ReceiveTimeout = new TimeSpan(0, 10, 00),
22                 MaxBufferSize = int.MaxValue,
23                 MaxReceivedMessageSize = int.MaxValue
24             }, new System.ServiceModel.EndpointAddress(address));
25             upload.UploadFileInfo info = new upload.UploadFileInfo();
26             info.AppName = request.appname; //应用名称
27             info.CompanyID = request.mer_id; //商户编号
28             info.FileType = upload.FileType.PIC;//图片文件
29             info.FileName = files.FileName;//文件名称
30             info.FileExterName = System.IO.Path.GetExtension(files.FileName);//文件扩展名
31             System.IO.Stream fileDateStream = files.OpenReadStream();
32             //files.CopyTo(fileDateStream);
33             long filelength = files.Length;
34             byte[] btyeImgDate = new byte[filelength];
35             fileDateStream.Read(btyeImgDate, 0, btyeImgDate.Length);
36             info.FileBuffer = btyeImgDate;//上传文件
37             upload.UploadResponseInfo response = client.UploadFile(info);
38             //uploadresponseinfo response = filefactory.uploadfile(info);
39             if (response.Result)
40             {
41                 return ApiResponseEntity.GetResponseEntity(new { src = response.UpLoadFileUrl.Replace('\\', '/') }, InterfaceStatus.Success, response.Message);
42             }
43             else
44             {
45                 return ApiResponseEntity.GetResponseEntity(InterfaceStatus.Error, response.Message);
46             }
47         }
View Code

upload为添加的wcf

 

标签:info,files,调用,System,upload,https,WCF,new
From: https://www.cnblogs.com/MycnBlogs7854/p/16938450.html

相关文章